Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change color of ListView items on focus and on click
    primarykey
    data
    text
    <p>i have a list View in my app (this is the xml layout):</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/arrayList" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textFilterEnabled="true" android:scrollbars="vertical" android:drawSelectorOnTop="true"&gt; &lt;/ListView&gt; </code></pre> <p>Each item of my list View is composed of two TextView:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TableLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/row_container" android:padding="5px" android:layout_height="wrap_content" android:background="@color/white" android:shrinkColumns="0"&gt; &lt;TableRow&gt; &lt;TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@+id/ description" android:id="@+id/description" android:textColor="@color/black" android:scrollHorizontally="true" android:singleLine="true"&gt;&lt;/TextView&gt; &lt;/TableRow&gt; &lt;TableRow&gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/result" android:textColor="@color/grey" android:maxLines="1" android:scrollHorizontally="true"&gt;&lt;/TextView&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; </code></pre> <p>I'm populating my listView from an ArrayAdapter, in this way:</p> <pre><code>public class Matches extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //set layout setContentView(R.layout.list_layout); // obtain reference to listview ListView listView = (ListView) findViewById(R.id.arrayList); ArrayAdapter&lt;Match&gt; arrayAdapter = new ArrayAdapter&lt;Match&gt;( this, R.layout.custom_row, R.id.description, createItems()) { @Override public View getView (int position, View convertView, ViewGroup parent){ Match item = getItem (position); LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.custom_row, null); TextView description = (TextView)rowView.findViewById(R.id.description); TextView result = (TextView)rowView.findViewById(R.id.result); description.setText(item.description + " Risultato: " + item.result ); result.setText(item.date + " " + item.hour); return rowView; } }; listView.setAdapter(arrayAdapter); </code></pre> <p>My goal is to be able to change the text color and the backgorund of these child views whenever the parent is selected or pressed.</p> <p>How can i do it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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