android - ListView with single choice to show unique selection -


i want have listview single choice. use checkedtextview , when user clicks on 1 row, update checkedtextview. if clicks on row, old selection retrieve "normal" ui , new selection takes new ui.

it works fine on nexus 7 (4.2.2) on galaxy s ii (4.0.4), have case have 2 rows selected , must click twice have right behavior.

i precise, have set property :

setchoicemode(listview.choice_mode_single); 

here layout :

<?xml version="1.0" encoding="utf-8"?>     <checkedtextview xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:custom="http://schemas.android.com/apk/res/com.ecab"     android:id="@+id/option"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_margin="10dp"     android:background="@drawable/ban_vhcl_list_off"     android:gravity="center_vertical"     android:paddingleft="10dp"     android:paddingright="10dp"     android:text="@string/fake" /> 

here adapter

private class optionsadapter extends arrayadapter<string> implements onitemclicklistener {     private final list<string> options;     public optionsadapter(list<string> poptions) {         super(vehiculeactivity.this, r.layout.vehicule_list_item);         options = poptions;     }      @override     public int getcount() {         return options.size();     }      @override     public string getitem(int position) {         return options.get(position);     }      @override     public view getview(int position, view convertview, viewgroup parent) {         if (convertview == null)             convertview = layoutinflater.from(vehiculeactivity.this).inflate(r.layout.vehicule_list_item, null);         checkedtextview option = (checkedtextview) convertview.findviewbyid(r.id.option);         option.settext(options.get(position));         if (!option.ischecked()) {             log.d(constants.d_tag, "is not checked");             option.setcompounddrawableswithintrinsicbounds(0, 0, 0, 0);             option.setbackgroundresource(r.drawable.ban_vhcl_list_off);         } else {             log.d(constants.d_tag, "is checked");             option.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.check_box, 0);             option.setbackgroundresource(r.drawable.ban_vhcl_list_on);         }         return convertview;     }      @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {         checkedtextview option = (checkedtextview) view.findviewbyid(r.id.option);         option.setchecked(true);         notifydatasetchanged();     } } 


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -