xml - Checkbox not showing in CheckedTextView Android -
i trying create list this:
<image><text> <checkbox>. so far text , image appears checkbox not. of code adapted here: http://www.learn2crack.com/2013/10/android-custom-listview-images-text-example.html
activity_filter_restaurants.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin"> <listview android:id="@+id/listfilter" android:layout_width="wrap_content" android:layout_height="wrap_content"> </listview> </relativelayout> list_filter_restaurants.xml
<?xml version="1.0" encoding="utf-8"?> <tablelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <tablerow> <imageview android:id="@+id/imgfilter" android:layout_height="100dp" android:layout_width="100dp" /> <checkedtextview android:layout_width="match_parent" android:layout_height="100dp" android:id="@+id/checkedtextview" android:layout_column="2" android:checkmark="?android:attr/listchoiceindicatormultiple" android:checked="false"/> </tablerow> </tablelayout> filterlist.java
public class filterlist extends arrayadapter<string> { private final activity context; private final string[] options; private final integer[] optionimageid; checkedtextview chktxttitle; public filterlist(activity context, string [] options, integer [] optionimageid){ super(context, r.layout.list_filter_restaurants,options); this.context = context; this.options = options; this.optionimageid = optionimageid; } @override public view getview (int position, view view, viewgroup parent){ layoutinflater inflater = context.getlayoutinflater(); view rowview= inflater.inflate(r.layout.list_filter_restaurants, null, true); chktxttitle = (checkedtextview) rowview.findviewbyid(r.id.checkedtextview); chktxttitle.setonclicklistener(new view.onclicklistener(){ @override public void onclick (view v){ if(chktxttitle.ischecked()) chktxttitle.setchecked(false); else chktxttitle.setchecked(true); } }); imageview imageview = (imageview) rowview.findviewbyid(r.id.imgfilter); chktxttitle.settext(options[position]); //chktxttitle.setcheckmarkdrawable(android.r.attr.listchoiceindicatormultiple); imageview.setimageresource(optionimageid[position]); homecoming rowview; } } filterrestaurants.java
public class filterrestaurants extends activity { listview filterlist; string [] options = { " vegetarian"," seafood"," western food"," indian/south asian"," halal/islamic"," chinese"," sandwiches", " deli", " coffee" }; integer [] optionsid = { r.drawable.vegan, r.drawable.seafood, r.drawable.westernfood, r.drawable.indian, r.drawable.halal, r.drawable.chinese, r.drawable.sandwiches, r.drawable.deli, r.drawable.coffee }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_custom_title); getwindow().setfeatureint(window.feature_custom_title, r.layout.header_food); setcontentview(r.layout.activity_filter_restaurants); customlist adaptor = new customlist(filterrestaurants.this,options,optionsid); filterlist = (listview) findviewbyid(r.id.listfilter); filterlist.setadapter(adaptor); // filterlist.setchoicemode(listview.choice_mode_single); filterlist.setchoicemode(listview.choice_mode_none); filterlist.setonitemclicklistener(new adapterview.onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, int position, long id){ toast.maketext(filterrestaurants.this,"yoy clicked @ "+options[+ position],toast.length_short).show(); } }); }
there simpler implementation of trying do. can seek this. don't need adaptor , allow go of filterlist.java class , list_filter_restaurants.xml file. have checkedtextview object in xml file , code below set image left of checkedtextview.
drawable imagedrawable = getbasecontext().getresources.getdrawable(r.drawable.your_image_name); ((checkedtextview) chktxttitle).setcompounddrawables(imagedrawable,null,null,null); android xml
No comments:
Post a Comment