Android : Error OnClick Button in Custom Alert Dialog Android

on Thursday, January 29, 2015


Hey i want to add Google+ Sign In button in Alert Dialog. So I need to make custom alert dialog right. I create it, but somehow it cant receive OnClick action. I search through web and stackoverflow but somehow i still cant solve this problem. This is my Alert Dialog :



AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

LayoutInflater layoutInflater = MainActivity.this.getLayoutInflater();
builder.setView(layoutInflater.inflate(R.layout.dialog_signin, null))
.setTitle("Create Post")
.setPositiveButton("Sign In", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!mGoogleApiClient.isConnecting()) {
mSignInClicked = true;
resolveSignInError();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

}
});

AlertDialog dialog = builder.create();

dialog.findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mGoogleApiClient.isConnecting()) {
mSignInClicked = true;
resolveSignInError();
}
}
});

dialog.show();


Please help me :) Thanks very much


0 comments:

Post a Comment