PlusOneButton on Android, how do I know if the user has clicked?
In my Android app, I give the option to click the Google +1 button.
This works great with the following code from the developer source material ( https://developers.google.com/+/mobile/android/recommend ):
mPlusClient = new PlusClient.Builder(this, this, this)
.clearScopes()
.build();
mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
Now I would like to detect when the user clicks that button, so I tried this:
mPlusOneButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(this, "Thanks for your +1", Toast.LENGTH_LONG).show();
}
});
But it doesn't do anything, it doesn't display the toast message.
Alternatively, I was thinking that the player double-clicked the button: first, it's a regular Button object that would make the plus button one visible, and the second one would be the plus button. but this is an awkward user interface
How can I detect that the user has clicked this button?
+2
source to share
3 answers
Use ActivityForResult to select a user.
mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() {
@Override
public void onPlusOneClick(Intent intent) {
startActivityForResult(intent, 0);
}
});
Check result code
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == -1) {
// OK or SHARE
} else {
//UNDO
}
}
+2
source to share