java - Add icon next to each item in a list -



java - Add icon next to each item in a list -

i have list item of strings, , assiate each item in navigationdrawer icon.

below list item called:

optionmenu = new string[] { "discover activities", "matches", "city selection", "preferences", "contact dooba" }; mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawerrelativelayout = (relativelayout) findviewbyid(r.id.left_drawer); mdrawerlist = (listview) findviewbyid(r.id.list_view_drawer); mdrawerlist.setadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_1, moptionmenu)); mdrawerlist.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { fragment fragment = null; switch (position) { case 0: fragment = new firstfragment(); break; case 1: fragment = new secondfragment(); break; case 2: fragment = new thirdfragment(); break; } fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction() .replace(r.id.content_frame, fragment).commit(); mdrawerlist.setitemchecked(position, true); mtitlesection = moptionmenu[position]; getsupportactionbar().settitle(mtitlesection); mdrawerlayout.closedrawer(mdrawerrelativelayout); } }); mdrawerlist.setitemchecked(0, true); mtitlesection = gettitle(); mtitleapp = gettitle(); mdrawertoggle = new actionbardrawertoggle(this, mdrawerlayout, r.drawable.logo8, r.string.drawer_open, r.string.drawer_close) { public void ondrawerclosed(view view) { getsupportactionbar().settitle(mtitlesection); activitycompat.invalidateoptionsmenu(mainactivity.this); } public void ondraweropened(view drawerview) { getsupportactionbar().settitle(mtitlesection); activitycompat.invalidateoptionsmenu(mainactivity.this); } }; mdrawerlayout.setdrawerlistener(mdrawertoggle); getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayuselogoenabled(true); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main_activity_actions, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { if (mdrawertoggle.onoptionsitemselected(item)) { homecoming true; } switch (item.getitemid()) { case r.id.action_settings: toast.maketext(this, "settings", toast.length_short).show(); ; break; default: homecoming super.onoptionsitemselected(item); } homecoming true; } @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); mdrawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); mdrawertoggle.onconfigurationchanged(newconfig); }

i wondering how add together number next item list string. example, matches (number 22) assistance appreciated.

write custom adapter , inflate list layout having imageview , textview.

<?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="match_parent" android:orientation="horizontal" > <imageview android:id="@+id/imageview1" android:layout_gravity="center" android:layout_width="48dp" android:layout_height="48dp" android:src="@drawable/ic_launcher" /> <textview android:id="@+id/textview1" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="25dp" android:text="textview" /> </linearlayout> public class customadapter extends baseadapter{ string [] result; context context; int [] imageid; private static layoutinflater inflater=null; public customadapter(mainactivity mainactivity, string[] prgmnamelist, int[] prgmimages) { // todo auto-generated constructor stub result=prgmnamelist; context=mainactivity; imageid=prgmimages; inflater = ( layoutinflater )context. getsystemservice(context.layout_inflater_service); } @override public int getcount() { // todo auto-generated method stub homecoming result.length; } @override public object getitem(int position) { // todo auto-generated method stub homecoming position; } @override public long getitemid(int position) { // todo auto-generated method stub homecoming position; } public class holder { textview tv; imageview img; } @override public view getview(final int position, view convertview, viewgroup parent) { // todo auto-generated method stub holder holder=new holder(); view rowview; rowview = inflater.inflate(r.layout.program_list, null); holder.tv=(textview) rowview.findviewbyid(r.id.textview1); holder.img=(imageview) rowview.findviewbyid(r.id.imageview1); holder.tv.settext(result[position]); holder.img.setimageresource(imageid[position]); rowview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub toast.maketext(context, "you clicked "+result[position], toast.length_long).show(); } }); homecoming rowview; } }

java android android-layout android-activity

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -