android - How to check if ListView item is checked or not -
i using list.setitemchecked(position, true) set items checked in listview, when clicked. have found no way however, of seeing if list item checked or not.
the listview item not have checkbox/radio , not use checkedtextview. listview set choice_mode_single.
listview onitemclick listener
@override public void onitemclick(adapterview<?> adapterview, view view, int position, long l) { list.setitemchecked(position, true); } adapter getview
@override public view getview(int position, view convertview, viewgroup parent) { inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); rowview = inflater.inflate(r.layout.rowlayout, parent, false); vg = parent; textview textview = (textview) rowview.findviewbyid(r.id.label); textview.settext(names[position]); textview textview2 = (textview) rowview.findviewbyid(r.id.tvvalue); textview2.settext(stock[position]); return rowview; } is there way check if list item checked or not? example, in onitemclick listener doing like:
if(position.ischecked()) { //do } i have looked on , cannot seem come without adding checkbox/radio layout , changing things around. appreciate advice, thanks!
edit:
the title little confusing, clarify: problem isn't item isn't selected/unselected, it's need handle second click on item selected. using simple if/else logic handle this, worked causes issues elsewhere in project, why wondering if there built-in functionality checking if item checked or not.
you can use list.isitemchecked(position). see docs
Comments
Post a Comment