There is an error when I call t开发者_JAVA技巧he intent startActivity (new Intent (this, Advogado1.class))
, How should I proceed to properly call this Intent
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Atenção");
alert.setMessage("Digite o Numero da OAB");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
int oab = Integer.parseInt(input.getText()
.toString());
// Do something with value!
if (oab == 1) {
startActivity(new Intent(this, Advogado1.class));
}
}
});
alert.setNegativeButton("Cancelar",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// Canceled.
}
});
alert.show();
The call to,
startActivity(new Intent(this, Advogado1.class));
should not use 'this', it should use,
startActivity(new Intent(NameOfYourActivity.this, Advogado1.class));
because this
refers to the anonymous class extending DialogInterface.OnClickListener
, and not your Activity
class. The Intent needs the caller class to be an instance of Activity.
精彩评论