Friday 15 July 2011

java - How do I get the item from each row of a listview? -



java - How do I get the item from each row of a listview? -

i wanna info in clicked row in listview.

this code , want access "id" value in each row od list view.

how item each row of listview?

how item each row of listview?

public class activitybookmark extends activity { private sqlitedatabase database; private listview lv; private int id; public arrayadapter<string> adapter; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.book_mark); lv = (listview) findviewbyid(r.id.bookmarklistview); animation animation = animationutils.loadanimation(this, r.anim.translate); lv.setlayoutanimation(new layoutanimationcontroller(animation)); arraylist<string> info = gedata(); adapter = new arrayadapter<string>(this, r.layout.bookmark_item, r.id.txtbookmarkitem, data); lv.setadapter(adapter); } public arraylist<string> gedata() { // todo auto-generated method stub database = sqlitedatabase.opendatabase(dbhelper.db_path + dbhelper.db_name, null, 0); cursor localcursor = database .rawquery( "select `rowid`,* `table1` 1=1 , `fav` '%true%' order `rowid` asc limit 0, 50000", null); arraylist<string> result = new arraylist<string>(); int title = localcursor.getcolumnindex("title"); //↓ want access id value onto onclickui method id = localcursor.getcolumnindex("id"); (localcursor.movetofirst(); !localcursor.isafterlast(); localcursor .movetonext()) { result.add(localcursor.getstring(title)); } homecoming result; } public void onclickui(view v) { switch (v.getid()) { case r.id.delfrombookmark: { //code retrive id of each row .... . toast.maketext(activitybookmark.this,v.getviewtreeobserver()+"", toast.length_short).show(); database.execsql("update table1 set fav='false' id=" + id + ""); list<string> newitems = gedata(); adapter.clear(); adapter.addall(newitems); adapter.notifydatasetchanged(); toast.maketext(getapplicationcontext(), "از لیست نشان شده ها حذف شد!", toast.length_short).show(); } break; default: break; } } }

you should implement onitemclicklistner

lv.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> adapter, view v, int position, long arg3) { //in method position , view of item clicked list } });

java android listview

No comments:

Post a Comment