android - notifyDataSetChanged removes last view -
i have used base adapter populate listview , when removing item list , calling adapter.notifydatasetchanged deleting last view. read other posts instead of deleting last view might hiding last view because count of list decreases 1. can me display required contents.
here adapter class
public class listoffav extends baseadapter { textview qid,ques,category; arraylist<hashmap<string,string>> flightarray=new arraylist<hashmap<string,string>>(); private static final string tag_qid = "qid"; private static final string tag_ques = "question"; private static final string tag_cat= "category"; context context; listoffav() { } public listoffav(arraylist<hashmap<string,string>> flightlist,context c){ log.v("constructor", string.valueof(flightarray.size())); flightarray=flightlist; context=c; } public int getcount() { // todo auto-generated method stub return flightarray.size(); } public object getitem(int arg0) { // todo auto-generated method stub return null; } public long getitemid(int position) { // todo auto-generated method stub return position; } public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service); view row; if(convertview==null||convertview.gettag()==null) row = inflater.inflate(r.layout.list_questions_main, parent, false); else row=convertview; qid=(textview)row.findviewbyid(r.id.tqid); ques= (textview) row.findviewbyid(r.id.tquestion); category = (textview) row.findviewbyid(r.id.tcategory); qid.settext(flightarray.get(position).get(tag_qid)); ques.settext(flightarray.get(position).get(tag_ques)); category.settext(flightarray.get(position).get(tag_cat)); return (row); } }
and updating as:
for (hashmap<string, string> map : favoritelist) { if (map.get(tag_qid).equals(t.gettext().tostring())) { favoritelist.remove(i); favadapter.notifydatasetchanged(); break; } i++; }
i solved problem calling favouritelistview.setadapter(favadapter) after notifying array adapter list associated has been changed i.e. refreshing list view adapter.
Comments
Post a Comment