Reputation: 59
I have a textView with OnClick method to navigate another activity. But, If i pressed that text it doesn't navigate. But If i used Button instead TextView, it works perfectly. Can't use OnClick method in TextView?
forgotpasstxt= (TextView) findViewById(R.id.txtForgotpPass);
/** Textview on click even.
*
*/
forgotpasstxt.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), ChangePassword.class);
startActivityForResult(myIntent, 0);}
});
XML.Login
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Forgot Password?"
android:id="@+id/txtForgotpPass"
android:clickable="true"
android:onClick="perform_action"
android:textColor="#ff3b5998"
android:layout_below="@+id/btnReset"
android:layout_centerHorizontal="true" />
Please help, I do not understand why the application crashes once the user clicks on the forgot password link.
Upvotes: 2
Views: 364
Reputation: 3578
You should remove the line:
android:onClick="perform_action"
this is because you are setting the TextView to do something onClick
twice. In your XML you are saying to do a method called perform_action
and in your code you are doing it correctly.
Since it's neater to use Java code for clicking and not XML I would suggest just removing the above line because the OnClickListener
is correct.
Upvotes: 2
Reputation: 949
delete forgotpasstxt.setOnClickListener and add perform_action method
public void perform_action(View view) {
Intent myIntent = new Intent(view.getContext(), ChangePassword.class);
startActivityForResult(myIntent, 0);
}
Upvotes: 0
Reputation: 10110
Remove this line:
android:onClick="perform_action"
You are setting the listener programmatically.
Upvotes: 5