android - How to navigate through data via Sqllite and ListActivity -


i'm displaying data sqlite using

listadapter adapter = new simplecursoradapter(this,             android.r.layout.simple_list_item_2,             employees,             new string[] {"firstname","lastname"},             new int[] {android.r.id.text1,android.r.id.text2},0);     getlistview().setadapter(adapter); 

empoyees - cursor.

data showing correctly, how row used sqlite duaring onclick on item list? example have 2 tables

1)category _id integer name text  2)articles _id integer name text categoryid (foreing key) 

so on first screen i'm displaying categorys, on list item click want display articles specified category, how that?

don't use cursor in adapter. build array , send in array instead. in array, typically list<mydatarecordholder> (where mydatarecordholder object you've created , filled data database), have set reference row id.

update:

create mydatarecordholder: (pseudo code)

list<mydatarecordholder> list = new list<mydatarecordholder>(); 

in loop fetch data:

mydatarecordholder record = new mydatarecordholder(); record.setid(cursor.get("rowid")) //set other pertinent data list.add(record); 

for adapter:

listadapter adapter = new simplecursoradapter(this,         android.r.layout.simple_list_item_2,         list,         new string[] {"firstname","lastname"},         new int[] {android.r.id.text1,android.r.id.text2},0); 

note, supplying list (list) adapter.

in onclick row, in adapter, current mydatarecordholder:

final myrecordholder record = getitem(position); string id = record.getid(); //make new db query based on id 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -