Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is an attribute in ListView called listSelector:</p> <blockquote> <p>Drawable used to indicate the currently selected item in the list.</p> </blockquote> <p><a href="http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:listSelector" rel="nofollow noreferrer">http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:listSelector</a></p> <hr> <p><strong>EDIT</strong> <em>after <a href="https://stackoverflow.com/users/1811719/stan">Stan</a> comment</em></p> <p>To ensure that a <code>ListView</code> stays selected, you should</p> <p>① Set the view's attribute <code>choiceMode</code> via xml or programmatically.</p> <p>② Use an adapter that uses views which implement <a href="http://developer.android.com/reference/android/widget/Checkable.html" rel="nofollow noreferrer"><code>Checkable</code></a> interface, like <a href="http://developer.android.com/reference/android/widget/CheckedTextView.html" rel="nofollow noreferrer"><code>CheckedTextView</code></a> (inside <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/frameworks/base/core/res/res/layout/simple_list_item_single_choice.xml?av=f" rel="nofollow noreferrer"><code>simple_list_item_single_choice</code></a> layout).</p> <p>File <code>TestActivity.java</code></p> <pre><code>public class TestActivity extends Activity { private static final int SINGLE_CHOICE = android.R.layout.simple_list_item_single_choice; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); String[] items = {"test 1", "test 2", "test 3"}; ListAdapter adapter = new ArrayAdapter&lt;String&gt;(this, SINGLE_CHOICE, items); ListView list = (ListView) findViewById(R.id.testList); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setAdapter(adapter); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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