eclipse - Can't Delete item in Android listView more than one time -
when select item in listview , use longclick,
i want remove listview after delete one
i can't delete other item need help.
what did wrong ?? :: think files[i] in if condition in onitemlongclick
but have no idea @ all..
public class screen2 extends activity implements adapterview.onitemlongclicklistener { listview listview1; private arrayadapter<string> adapter1; private file[] files; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.screen2); setupgui(); adapter1 = new arrayadapter<string>(this,android.r.layout.simple_list_item_1); file f = new file("/sdcard/"); files = f.listfiles(); for(file ff:files){ if(ff.isfile() ==true){ adapter1.add("file " + ff.getname()); } else if(ff.isdirectory() == true){ adapter1.add("dir "+ ff.getname()); } } listview1.setadapter(adapter1); listview1.setonitemlongclicklistener(this); } public void setupgui() { listview1 = (listview) findviewbyid(r.id.listview1); } @override public boolean onitemlongclick(adapterview<?> adapterview, view view, int i, long l) { if (files[i].isfile() == true){ string fname = "/sdcard/" + files[i].getname(); aa.killsdfile(fname); aa.msg(this, "file removed", 0); adapter1.remove((string)adapterview.getitematposition(i)); log.d("file:", fname+" killed"); } return true; } }
you need refresh listview data notifydatasetchanged() function , need recall function on long press event
file f = new file("/sdcard/"); files = f.listfiles(); for(file ff:files){ if(ff.isfile() ==true){ adapter1.add("file " + ff.getname()); } else if(ff.isdirectory() == true){ adapter1.add("dir "+ ff.getname()); } } listview1.setadapter(adapter1);
check , pls let me know if issue.
Comments
Post a Comment