我在调用意图startActivity (new Intent (this, Advogado1.class))
时出错,我该如何正确调用此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();
答案 0 :(得分:2)
致电,
startActivity(new Intent(this, Advogado1.class));
不应该使用'this',它应该使用,
startActivity(new Intent(NameOfYourActivity.this, Advogado1.class));
因为this
指的是扩展DialogInterface.OnClickListener
的匿名类,而不是Activity
类。 Intent需要调用者类是Activity的实例。