android - ListView is not populating -
i created adapter populate custom listview , when ran on emulator activity blank. plz help. sure i'm missing 'cause new java & android. code snippets correct , pointers appreciated. thnx!
my activity:
public class list_ac3 extends listactivity { /** * -- called when activity first created * =================================================================== */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.list_view2); displayresultlist(); } private void displayresultlist() { cursor databasecursor = null; domainadapter databaselistadapter = new domainadapter(this, r.layout.list_item, databasecursor, new string[] {"label", "title", "description"}, new int[] { r.id.label, r.id.listtitle, r.id.caption }); databaselistadapter.notifydatasetchanged(); setlistadapter(databaselistadapter); } }
my adapter:
public class domainadapter extends simplecursoradapter{ private layoutinflater minflater; string extstoragedirectory; public domainadapter(context context, int layout, cursor c, string[] from, int[] to) { super(context, layout, c, from, to); minflater = layoutinflater.from(context); } public view getview(int position, view convertview, viewgroup parent) { viewholder holder; if (convertview == null) { convertview = minflater.inflate(r.layout.list_item, null); holder = new viewholder(); holder.text1 = (textview) convertview.findviewbyid(r.id.label); holder.text2 = (textview) convertview.findviewbyid(r.id.listtitle); holder.text3 = (textview) convertview.findviewbyid(r.id.caption); convertview.settag(holder); } else { holder = (viewholder) convertview.gettag(); } extstoragedirectory = environment.getexternalstoragedirectory().tostring(); file dbfile = new file(extstoragedirectory+ "/aero-technologies/flydroid/db/flydroid.db"); sqlitedatabase db = sqlitedatabase.openorcreatedatabase(dbfile, null); cursor data = db.rawquery("select * ac_list", null); data.movetoposition(position); int label_index = data.getcolumnindex("label"); string label = data.getstring(label_index); int title_index = data.getcolumnindex("title"); string title = data.getstring(title_index); int description_index = data.getcolumnindex("description"); string description = data.getstring(description_index); holder.text1.settext(label); holder.text2.settext(title); holder.text3.settext(description); return convertview; } static class viewholder { textview text1; textview text2; textview text3; } }
the list_view2.xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <relativelayout android:layout_width="fill_parent" android:layout_height="30dip" android:padding="4dip" android:background="@drawable/gradient" > <imagebutton android:id="@+id/homebtn" android:src="@drawable/ic_menu_icon" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignparentleft="true" android:background="@null" /> <textview android:id="@+id/titlebartitle" android:layout_centerinparent="true" android:layout_width="wrap_content" android:layout_height="match_parent" android:textsize="18sp" /> <imagebutton android:id="@+id/toolbtn" android:src="@drawable/ic_menu_list" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignparentright="true" android:background="@null" /> </relativelayout> <listview android:id="@id/android:list" android:layout_height="wrap_content" android:layout_width="fill_parent" /> </linearlayout>
and list_item.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/acitem" style="@style/listitem" > <textview android:id="@+id/label" style="@style/listacronym" /> <textview android:id="@+id/listtitle" style="@style/listtitle" /> <textview android:id="@+id/caption" style="@style/listdiscription"/> <imageview style="@style/listnexticon" /> </relativelayout>
the google notepad tutorials should iirc should using cursors passed listview
Comments
Post a Comment