Reputation: 800
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
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
Reputation: 1595
try it with
v.setBackgroundColor(R.Color.Red);
in your onClick
method
Upvotes: 0