CheckedTextView in ListVew - setChecked() does not work for Android 2.3 -
i have listview
specifies listselector
:
<listview android:id="@+id/listview" android:listselector="@drawable/list_selector" android:layout_width="match_parent" android:layout_height="match_parent" />
every list item has checkedtextview
:
<checkedtextview android:id="@+id/checkedtextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="checkedtextview" />
i need when clicking on row list, clicked item remain checked, how it:
listview.setchoicemode(listview.choice_mode_single); listview.setonitemclicklistener(this); // .... @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { checkedtextview checkedtextview = (checkedtextview) view.findviewbyid(r.id.checkedtextview); checkedtextview.setchecked(true); }
it works fine on android 4.0, not work on android 2.3. appreciate if give clue why happening.
i dont know why happening have idea implement in way
assuming using custom adapter load list items
set onclicklistener checkedtextview @ time of view creation in custom adapter
final checkedtextview ct = (checkedtextview) view .findviewbyid(r.id.checkedtextview); ct.settext("text"); ct.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // ever want perform here if(ct.ischecked()){ } else { } } });
another option here
Comments
Post a Comment