Skip to content Skip to sidebar Skip to footer

Change The Color Of Text In Textview In Table Row On Row Click

I have a table with some rows having a textview and imageview.I am changing the background of row on click using a selector drawable.I also need to change the color of text and th

Solution 1:

A simple way to achieve this is to set the onClick property for the textview in your xml

android:onClick="changeColor"

Then in the activity that the view belongs to have a method

publicvoidchangeColor(View v){
    v.setBackgroundColor(color);
}

v will be the view calling the changeColor() method (hence it's the one you want to change the color of)

You can extend this (or write other methods to set as onClick methods for your other views) to change properties of other views by casting v to the appropriate View (i.e. TextView to change the text color, or ImageView for changing an image drawable)

and if you want to find exactly what view is calling the method you can switch on v.getId() with the case statements being the ids set in R i.e. the ones you set with the android:id="@+id/name property

Solution 2:

Set OnTouchListener for Table row as in android TextView : Change Text Color on click

In the ontouch event get the textview child from the row and change its color ..

Post a Comment for "Change The Color Of Text In Textview In Table Row On Row Click"