Reputation: 2018
<uses-sdk android:minSdkVersion="8" />
onClick method defined in xml
<TextView
android:id="@+id/titlemainpage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Social To Dos"
android:onClick="testing" />
testing method used in java class is
public void testing(View v){
Toast.makeText(this, "Clicked", Toast.LENGTH_LONG).show();
textview.setTextColor(Color.CYAN);
}
Upvotes: 15
Views: 26957
Reputation: 421
You have to set setOnClickListener on onCreateView e.g. mBinding.llSpeedHome.setOnClickListener(this)
Upvotes: 0
Reputation: 757
Dont forget to remove the on click listener (if you have set that programmatically inside the containing activity).
Upvotes: 1
Reputation: 11032
Buttons are by default clickable but TextViews are not. Unless you explicitly setup the onClick listener at runtime textViews won't be clickable on pre-Lollipop devices.
So if you want to make a TextView clickable which is hooked with a listener in XML layout file you should use
android:clickable="true"
Upvotes: 2
Reputation: 18489
Add one more attribute to the textview in xml:
android:clickable="true"
Upvotes: 37
Reputation: 4094
I might be wrong but I think you have to implement a listener rather than using a simple function.
Check this website.
Upvotes: -3