Note that there are some explanatory texts on larger screens.

plurals
  1. POListView with single choice to show unique selection
    text
    copied!<p>I want to have a listview with a single choice. I use a CheckedTextView and when the user clicks on one row, i update the CheckedTextView. If he clicks on another row, the old selection retrieve the "normal" UI and the new selection takes the new UI.</p> <p>It works fine on nexus 7 (4.2.2) but on galaxy S II (4.0.4), i have a case where i have two rows selected and i must click twice to have the right behavior.</p> <p>I precise, i have set this property :</p> <pre><code>setChoiceMode(ListView.CHOICE_MODE_SINGLE); </code></pre> <p>Here is my layout : </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" /&gt; </code></pre> <p>Here is my adapter</p> <pre><code>private class OptionsAdapter extends ArrayAdapter&lt;String&gt; implements OnItemClickListener { private final List&lt;String&gt; options; public OptionsAdapter(List&lt;String&gt; 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&lt;?&gt; parent, View view, int position, long id) { CheckedTextView option = (CheckedTextView) view.findViewById(R.id.option); option.setChecked(true); notifyDataSetChanged(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload