Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you considered using a <a href="http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList" rel="nofollow" title="selector">Selector</a>? In ignorance of how your buttonAdapter works or what you're pulling it from, you can set the background drawable of any View to change according to its state using selectors.</p> <p>If your selector is defined like so (assuming the presence of appropriate drawables, of course):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:state_focused="true" android:drawable="@drawable/list_item_pressed" /&gt; &lt;item android:state_pressed="true" android:drawable="@drawable/list_item_pressed" /&gt; &lt;item android:state_selected="true" android:state_activated="true" android:drawable="@drawable/list_item_selected" /&gt; &lt;item android:state_activated="true" android:drawable="@drawable/list_item_selected" /&gt; &lt;item android:state_selected="true" android:drawable="@android:color/black" /&gt; &lt;item android:drawable="@android:color/transparent" /&gt; &lt;/selector&gt; </code></pre> <p>And then set your GridView's choice mode to single Choice: </p> <pre><code>&lt;GridView ... android:choiceMode="singleChoice" /&gt; </code></pre> <p>This lets the OS take care of everything for you in terms of remembering which position is selected in the list and then clearing it out for you when you've clicked another one</p>
 

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