Reputation: 185
This is the xml for the textview
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIGN IN"
android:id="@+id/signInTV"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_weight="1"
android:background="#EB7B59"
android:textColor="#524656"
android:clickable="true"
android:onClick="signInButton"
android:focusableInTouchMode="false"/>
This is the code:
public void signInButton(View view) {
TextView signInTV = (TextView) findViewById(R.id.signInTV);
signInTV.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent showSignInActivity = new Intent(v.getContext(), SignInActivity.class);
startActivity(showSignInActivity);
}
});
}
Why is it that i can still only double tap on the textview and not single tap?
Upvotes: 0
Views: 1010
Reputation: 10547
You are resetting the OnClickListener
with the first tap. The second tap then uses the OnClickListener
with the intent
Your code should only be like this:
public void signInButton(View view) {
Intent showSignInActivity = new Intent(v.getContext(), SignInActivity.class);
startActivity(showSignInActivity);
}
Upvotes: 0
Reputation: 2276
Change your code to:
public void signInButton(View view) {
if(view.getId() == R.id.signInTV){
Intent showSignInActivity = new Intent(v.getContext(), SignInActivity.class);
startActivity(showSignInActivity);
}
}
You already have an OnClickListener specified in the XML code, you add another listener inside the first one. That's why you have to click two times.
Upvotes: 0
Reputation: 69388
You are already in the click event handler, and you are receiving the clicked View as parameter so there's no need to find it again. This should start the Activity.
public void signInButton(View view) {
Intent showSignInActivity = new Intent(v.getContext(), SignInActivity.class);
startActivity(showSignInActivity);
}
Upvotes: 1