android - Acessing data form database on click of listView -
i have listview in activity1 have few items word database . user clicks on item in listview , navigate activity2 should show details of word stored in database column word, definitions . appears in screen2 depends on item clicked in screen 1
for ex - user clicks in screen 1 - words starting come in screen 2. there way pass row id in next screen word , definition database can displayed.
thank in adv.. code first activity:
lv.setonitemclicklistener(new adapterview.onitemclicklistener() {
@override public void onitemclick(adapterview parent, view v, int position, long id) { // todo auto-generated method stub cursor c = mdictcursor; c.movetoposition(position); intent = new intent(firstactivity.this, secondactivity.class); bundle bundle=new bundle(); //intent.putextra("position",position); bundle.putlong(dbadapter.key_rowid, id); bundle.putstring(dbadapter.key_title, c.getstring( c.getcolumnindexorthrow(dbadapter.key_title))); bundle.putstring(dbadapter.key_definition, c.getstring( c.getcolumnindexorthrow(dbadapter.key_definition))); i.putextras(bundle); startactivity(i); } secondactivity code:
bundle extras = getintent().getextras();
mrowid = extras.getlong(dbadapter.key_rowid); string title = extras.getstring(dbadapter.key_title); string body = extras.getstring(dbadapter.key_definition); textview word = (textview) findviewbyid(r.id.word); word.settext(title); textview definition = (textview) findviewbyid(r.id.definition); definition.settext(body); } whenever clicking listview item showing dialog force close. please help...
you can use intent object putextra(string name, int value) method in screen1(see1) , pass intent object screen2,in screen2 use getintextra(string name, int defaultvalue) method of intent object(see 2). 1.use startactivity(intent intent) method in screen1 2.use getintent() method in screen2 intent object passed in screen1
Comments
Post a Comment