android - Arraylist display selected listview to textview -
i'm noob in android. i've got code someone's blog.
he made simple database query , populate arraylist in listview.
how value each selected item in listview text view in new activity?
here's arraylist code:
public arraylist<arraylist<object>> rowtable() { arraylist<arraylist<object>> fillarray = new arraylist<arraylist<object>>(); cursor cur; try { cur = db.query(table_test, new string[] { row_id, row_name, row_class }, null, null, null, null, null); cur.movetofirst(); if (!cur.isafterlast()) { { arraylist<object> filllist = new arraylist<object>(); datalist.add(cur.getlong(0)); datalist.add(cur.getstring(1)); datalist.add(cur.getstring(2)); dataarray.add(filllist); } while (cur.movetonext()); } } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); log.e("error database", e.tostring()); } return fillarray; }
and here's listview code.
private void getarraylist() { // todo auto-generated method stub arraylist<arraylist<object>> getdata = dtbase.rowtable();// name = new string[getdata.size()]; (int x = 0; x < getdata.size(); x++) { arraylist<object> getrow = getdata.get(x); name[x] = getrow.get(1).tostring(); } arrayadapter<string> sname = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, name); lv.setadapter(sname); }
can me?
it's easy selected item
here method need override.
listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position,long arg3) { ... } }
then use position argument access arraylist display in textview.
Comments
Post a Comment