android - Single Choice Lists and onClick events -
i have choice_mode_single list 3 rows. how place onclick event changes value of arbitrary variable, if row 1 clicked, say, value of x = 1, , when row 2 clicked, value of x = 2, etc.?
public class list extends listactivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setlistadapter(new arrayadapter<string>(this, android.r.layout.simple_list_item_single_choice, genres)); final listview listview = getlistview(); listview.setitemscanfocus(false); listview.setchoicemode(listview.choice_mode_single); } private static final string[] genres = new string[] {"barre", "buffumville","hodges"}; }
its quite simple..rather extending listactivity extend activity , declare listview in xml file below:
<listview android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"/> initialize listview in activity:
listview listview=(listview) findviewbyid(r.id.list); and after setting adapter did,set item click listener of listview below in code:
listview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(getbasecontext(), genres[position], toast.length_short).show(); } }); by doing desired value of position of listview. surely result want.
Comments
Post a Comment