Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why dont you try defining <code>template</code> inside the loop?</p> <pre><code>if (items.size() &gt; 0) { for (int i = 0; i &lt; items.size(); i++) { View template = inflate(getContext(), R.layout.views_custom_list_item, null); template.setBackgroundDrawable(getProperBackgroundDrawable(i, items.size() - 1)); TextView text = (TextView)template.findViewById(R.id.custom_list_text); text.setText(items.get(i)); Button button = (Button)template.findViewById(R.id.custom_list_button); button.setId(i); button.setBackgroundDrawable(backgroundButton); button.setOnClickListener(callListener); addView(template); } } </code></pre> <p>I hope this helps</p> <p><strong>EDIT</strong></p> <p>Try using this for your selector, and also try adding it in the XML.</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;!-- Non focused state --&gt; &lt;item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/button_phone"" /&gt; &lt;!-- Focused state --&gt; &lt;item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/button_phone_over" /&gt; &lt;!-- Pressed state --&gt; &lt;item android:state_pressed="true" android:drawable="@drawable/button_phone_over" /&gt; &lt;/selector&gt; </code></pre> <p>I have a feeling that the problem is that you are reusing the drawable in the code, so if you are not doing it in the XML then create a new drawable for each background, instead of reusing the one.</p>
    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