<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);
}
When the user clicks a button, the Button object receives an on-click event. To define the click event handler for a button, add the android:onClick attribute to the <Button> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event.
To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
Add one more attribute to the textview in xml:
android:clickable="true"
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"
Dont forget to remove the on click listener (if you have set that programmatically inside the containing activity).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With