database - Android Studio ListView from SQLite -
i'm working on android studio.i have problem displaying data sqlite database on listview. here method take data sqlite(it works well,checked)
public list<terminy> getallitems(){ list<terminy> itemlist = new arraylist<terminy>(); string selectquery = "select id,data terminy wolny = 1"; sqlitedatabase database = this.getwritabledatabase(); cursor cursor = database.rawquery(selectquery, null); if(cursor.movetofirst()){ do{ terminy termin = new terminy(); termin.setid2(integer.parseint(cursor.getstring(0))); termin.setdata(cursor.getstring(1)); itemlist.add(termin); }while(cursor.movetonext()); } cursor.close(); return itemlist; }
and there method put data listview
public void buttonlista(view v) { arrayadapter<terminy> adapter; arraylist<terminy> lista; databasehelper helper = new databasehelper(this); listview listview = (listview) findviewbyid(r.id.listview); lista = new arraylist<>(helper.getallitems()); adapter = new arrayadapter<terminy>(this,r.layout.activity_panel_uzytkownik, lista); listview.setadapter(adapter); adapter.notifydatasetchanged();
logcat error
com.example.czou.proojekt e/arrayadapter: must supply resource id textview com.example.czou.proojekt d/androidruntime: shutting down vm com.example.czou.proojekt w/art: suspending threads took: 02-08 17:47:59.352 1779-1779/com.example.czou.proojekt e/androidruntime: fatal exception: main process: com.example.czou.proojekt, pid: 1779 java.lang.illegalstateexception: arrayadapter requires resource id textview
could 1 me ? have read many tutorials far , still don't know how solve problem :(
take @ answer
or try using separate adapter
(extends arrayadapter
) have full control on layout , each piece of it.
here tutorial using arrayadapter link
another tutorial on how use sqlite listview link
Comments
Post a Comment