how to Get data from SQLite database to intent through “onItemClick” on item in ListView Android -
i apologize in advance, indonesia, english language may not .. translate me through google translate
i'm making android app associated sqlite. problem have, want display info database according selected listview. application application made tour guide.
while running application, performing of category of existing attractions. if 1 of selected categories, such category: nature, show list of names exist in nature in form of database listview.
i managed here.
after that, if take 1 of name of nature, such as: losari, show description of losari according database.
i confused how display described above .. please help me
this file alam.java displaying listview info retrieved database
dbadapter db; protected cursor cursor; protected listadapter adapter; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.alam); final listview dftalam = (listview)findviewbyid(r.id.lv); final dbadapter db = new dbadapter(this); arraylist<dft_alam> dft_alam = db.getallalam(); dftalam.setadapter(new myadapter(this, dft_alam)); dftalam.setonitemclicklistener(new onitemclicklistener() { private string nama; private string alamat; private string desk; public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub string selecteditem = (string) dftalam.getitematposition(arg2); string query = "select nama, alamat, desk wisata nama = '" + selecteditem + "'"; sqlitedatabase dbs = db.getreadabledatabase(); cursor result = dbs.rawquery(query, null); result.movetofirst(); nama = result.getstring(result.getcolumnindex("nama")); alamat = result.getstring(result.getcolumnindex("alamat")); desk = result.getstring(result.getcolumnindex("desk")); intent intent = new intent(android.content.intent.action_view, null, null, deskalam.class); startactivity(intent); } }); } public void onclick(view v) { } }
this file deskalam.java display description of selected alternative in listview
dbadapter db; textview nama = null; textview alamat = null; textview desk = null; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.desk); textview nama = (textview)findviewbyid(r.id.nm); textview alamat = (textview)findviewbyid(r.id.alm); textview desk = (textview)findviewbyid(r.id.desk); dbadapter db = new dbadapter (this); db.opendatabase(); cursor c = (cursor) db.getallalam(); if (c.movetofirst()){ do{ tampil(c); }while (c.movetonext()); } } public void tampil(cursor c) { // todo auto-generated method stub toast.maketext(this, c.getstring(4) + "\n" + c.getstring(5) + "\n" + c.getstring(6), toast.length_long).show(); } }
please prepare if goes wrong or less of source code mentioned above
here need in onitemclick:
listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent intent = new intent(thisactivity.this, nextactivity.class); intent.putextra("chosen", position); startactivity(intent); } });
and how info in next intent:
int chosenposition; yourobject chosenobject; bundle extras = getintent().getextras(); if (extras != null) { //here id item chosenposition= (int)extras.getint("chosen"); } //here utilize id object database or whatever chosenobject = database.getyourobject(chosenposition+ 1);
android sqlite listview onitemclicklistener onitemclick
No comments:
Post a Comment