Reputation: 137
I have a textView in which i have set the color as transparent in xml
android:background="#ffffff"
Now i have written the code to change the image of the textView onClick
t1.setBackgroundResource(R.drawable.fslash);
but it does not seem to do anything onClick of the textView.
Please help
Upvotes: 0
Views: 230
Reputation: 744
You have to implement click method like this
textview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
// Your Code
} catch (Exception e) {
}
}
});
Upvotes: 1
Reputation: 829
If you want to click on the TextView, you have to set the clickable attribute to true. Otherwise it will not listen to any click! You can do that in code or in the xml file:
Code:
t1.setClickable(true);
XML:
android:clickable="true"
Upvotes: 0
Reputation: 5531
try setting:
android:clickable="true"
or
you can also do in XML:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<android:background="@drawable/yourimg" />
</item>
<item android:background="#000000" /> <!-- default -->
</selector>
Upvotes: 0
Reputation: 6037
try this,
t1.setOnClickListener(new OnClickListener(){
private void onClick(View v){
TextView txt=(TextView)v.findViewById(R.id.txtid);
txt.setBackgroundResource(R.drawable.fslash);
}
});
Upvotes: 0