Dynamically add image to android listView item -
i'm trying dynamically add image listview
row. have create custom cursor or something? don't know put code change image source.
thanks.
here activity,
public class viewplayersactivity extends activity { listview namelist; mysqliteadapters adapter_ob; mysqlitehelper helper_ob; sqlitedatabase db_ob; button registerbtn; cursor cursor, cursor2, cursor3; string context; public static final string prefs = "exampleprefs"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_view_players); namelist = (listview) findviewbyid(r.id.listview); adapter_ob = new mysqliteadapters(this); bundle extras = getintent().getextras(); sharedpreferences exmaple = getsharedpreferences(prefs, 0); context = exmaple.getstring("teamname", "cant find team"); string[] = {helper_ob.key_fname, helper_ob.key_lname}; int[] = { r.id.tv_fname, r.id.tv_lname}; cursor = adapter_ob.queryname(context); simplecursoradapter cursoradapter = new simplecursoradapter(this, r.layout.row, cursor, from, to); namelist.setadapter(cursoradapter); namelist.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub bundle passdata = new bundle(); cursor listcursor = (cursor) arg0.getitematposition(arg2); int nameid = listcursor.getint(listcursor .getcolumnindex("p_id")); passdata.putint("keyid", nameid); intent passintent = new intent(viewplayersactivity.this, editplayeractivity.class); passintent.putextras(passdata); startactivity(passintent); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.view_players, menu); return true; } // method refreshes view show record updates & deletes public void onresume() { super.onresume(); cursor.requery(); }
here current xml row. i'm adding static image here need dynamic.
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/listcontainer" android:orientation="horizontal" > <textview android:id="@+id/tv_fname" android:layout_width="210dp" android:layout_height="wrap_content" /> <textview android:id="@+id/tv_lname" android:layout_width="250dp" android:layout_height="wrap_content" android:paddingtop="15dp" android:layout_marginleft="20dp" /> <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon_center" /> </linearlayout>
here listview looks after adding few rows.
Comments
Post a Comment