Issue
I have a simple layout file that contains only one button:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="signIn"/>
</RelativeLayout>
And in my MainActivity, I have this method:
public void signIn(View v) {
Toast.makeText(getApplicationContext(), "Button clicked", Toast.LENGTH_LONG).show();
}
But nothing happens. I have also tried to add:
android:clickable="true"
But is not working. If set on click listener on the button, it works. How to set onClick directly from the layout file?
Solution
SignInButton is a custom view which extend View component. The doc indicates to use the setOnClickListener
directly in your activity or fragment.
Look the SignInButton source code. onClick
is override and need a mClientListener
to work. The only way to set the mClientListener
, it's to use the setOnClickListener
.
Simply use the OnClick listener directly in your activity or fragment :
signInButton = (SignInButton)findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(this);
Answered By - Johann67
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.