android - SimpleCursorAdapter - set 2 columns to 1 view -
i have sqlite datebase displaying data in listview
simplecursoradapter
. have 2 columns want displey them in 1 textview
. how can that? thanks
try code , may you
method calling listview oncreate
private void populatelistviewfromdb1() { cursor cursor = helper1.getalldata(sharedemail); startmanagingcursor(cursor); string[] productname = new string[] { databasehelper.key_namevalue, databasehelper.key_type, }; int[] viewproduct = new int[] { r.id.textview1, }; // create adapter mysimplecursoradapter mycursoradapter = new mysimplecursoradapter (this, r.layout.listview, cursor, productname, viewproduct); listview list = (listview) findviewbyid(r.id.listview1); list.setadapter(mycursoradapter); } }
mysimplecursoradapter.java
public class mysimplecursoradapter extends simplecursoradapter { public mysimplecursoradapter(context context, int layout, cursor cur, string[] from, int[] to) { super(context, layout, cur, from, to); } @suppresswarnings("static-access") @override public view newview(context con, cursor c, viewgroup arg2) { layoutinflater inflater = (layoutinflater) con .getsystemservice(con.layout_inflater_service); view retview = inflater.inflate(r.layout.listview, null); return retview; } public void bindview(view v, context context, cursor c) { string pname = c.getstring(c.getcolumnindex(databasehelper.key__namevalue)); string issuetype = c.getstring(c.getcolumnindex(databasehelper.key_type)); textview name_text = (textview) v.findviewbyid(r.id.textview1); name_text.settext(pname +":"+ issuetype); } }
Comments
Post a Comment