Android getView : Why getView not called? -


i add 2 buttons (add , delete) control list view, when delete item, item won't disappear in listview, when slide on listview, new item disappears. getview() in adapter won't called after delete item unless touch screen or slide on listview. can tell me why?

my xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/locationlist_layout"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >"      <relativelayout         android:id="@+id/locationlisttitle_layout"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:gravity="center_vertical"          android:background="#add8e6">          <imageview             android:id="@+id/iv_menu2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:padding="5dp"             android:src="@drawable/img_menu" />          <textview             android:id="@+id/txtv_locationmanagetitle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerinparent="true"             android:text="manage location list"             android:textsize="20sp" />          <imageview             android:id="@+id/iv_addlocation"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centervertical="true"             android:layout_torightof="@+id/txtv_locationmanagetitle"             android:src="@drawable/addlocation" />          <imageview             android:id="@+id/iv_deletelocation"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centervertical="true"             android:layout_torightof="@+id/iv_addlocation"             android:src="@drawable/deletelocation" />      </relativelayout>      <listview         android:id="@+id/lv_locations"         android:layout_height="500dp"         android:layout_width="fill_parent" /> </linearlayout> 

my button click event handler

ivbtn_deletelocation.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             //remove selected items locationlist             collections.sort(liststr);             (int = liststr.size()-1; >= 0; i--) {                 log.i("zhijianw", "remove"+liststr.get(i));                 log.i("zhijianw", "remove"+locationlist.get(integer.parseint(liststr.get(i))).get("txtv_locationitem"));                 string remlocation = locationlist.get(integer.parseint(liststr.get(i))).get("txtv_locationitem").tostring();                 locationlist.remove(integer.parseint(liststr.get(i)));                 removelocation(remlocation);             }              liststr = new arraylist<string>();             locationsadapter.notifydatasetchanged();         } }); 

my adapter

  public myadapter(context context, list<hashmap<string, object>> list, int resource, string[] from, int[] to) {             this.context = context;             this.list = list;             keystring = new string[from.length];             idvalue = new int[to.length];             system.arraycopy(from, 0, keystring, 0, from.length);             system.arraycopy(to, 0, idvalue, 0, to.length);             inflater = layoutinflater.from(context);             init();             log.i("zhijianw", "my adapter called");      }      public void init() {             isselected = new hashmap<integer, boolean>();             (int = 0; < list.size(); i++) {                     isselected.put(i, false);             }     }      @override     public int getcount() {         log.i("zhijianw", "get count called");               return list.size();      }      @override     public object getitem(int arg0) {         log.i("zhijianw", "get item called");             return list.get(arg0);     }      @override     public long getitemid(int arg0) {             return arg0;     }      @override     public view getview(int position, view view, viewgroup arg2) {         init();         log.i("zhijianw", "get view called");                    viewholder holder = null;         if (view == null) {                 holder = new viewholder();                 view = inflater.inflate(r.layout.location_item, null);                 holder.tv = (textview) view.findviewbyid(r.id.txtv_locationitem);                 holder.cb = (checkbox) view.findviewbyid(r.id.cb_locationitem);                 view.settag(holder);         } else {                 holder = (viewholder) view.gettag();         }         hashmap<string, object> map = list.get(position);         if (map != null) {                 itemstring = (string) map.get(keystring[0]);                 holder.tv.settext(itemstring);         }         holder.cb.setchecked(isselected.get(position));         return view;     }  } 

set listview adapter

lv_menu = (listview) menu_view.findviewbyid(r.id.lv_menu); lv_menu.setadapter(new arrayadapter<string>(this, r.layout.menu_item,   r.id.txtv_menuitem, menuchoices)); 

the locationsadapter not appear getting set same adapter used lv_menu.setadapter() locationsadapter.notifydatasetchanged() not invalidating lv_menu. try lv_menu.invalidate() directly in onclick() function.

i reload list adapters scratch whenever deleting items, when checkbox items involved, in order keep things getting out of sync.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -