user1364684
user1364684

Reputation: 800

How to change the textview color of item listview when that item is on click?

I have a ListView and each item have a TextView.

I would like change the item TextView color, for example, when user click in that item.

any ideas, examples or tutorials?

thanks

Upvotes: 0

Views: 1115

Answers (2)

Mouna Cheikhna
Mouna Cheikhna

Reputation: 39638

use a list of states.

For example, create a file called bg_states.xml in your drawable folder an:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_selected="true"
   android:drawable="@color/blue" ></item>
<item
    android:state_pressed="true"
   android:drawable="@color/blue" ></item>
<item 
    android:drawable="@color/black" /> 
</selector> 

and define it as a background for your TextView:

<TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:background="@drawable/bg_states"

Upvotes: 2

Boe-Dev
Boe-Dev

Reputation: 1595

try it with

v.setBackgroundColor(R.Color.Red);

in your onClick method

Upvotes: 0

Related Questions