我在2.1和更低的版本越來越onCreateDialog方法中的異常?
09-20 12:42:26.697: ERROR/AndroidRuntime(721): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dashboardnew/com.dashboardnew.GmailFetchActivity}: java.lang.IllegalArgumentException: Activity#onCreateDialog did not create a dialog for id 1
例外。
@Override
protected Dialog onCreateDialog(int id) {
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alertdialog_gmail, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Gmail login");
alert.setMessage("Enter your username and password");
// Set an EditText view to get user input
alert.setView(textEntryView);
final EditText username = (EditText) textEntryView.findViewById(R.id.edit_username);
final EditText password = (EditText) textEntryView.findViewById(R.id.edit_password);
alert.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String user=username.getText().toString();
String pass=password.getText().toString();
new FetchGmail().execute(user+"@gmail.com",pass);
progressDialog2.show();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
// TODO Auto-generated method stub
return super.onCreateDialog(id);
}
它的工作thks !! cnüPLZ告訴我什麼是問題 – Harinder
我不是很確定爲什麼super.onCreateDialog(ID)在這裏不工作,但在您的代碼警報是一個AlertDialog.Builder實例得到一個你需要調用create()的對話框,如果你不需要調用super方法提供您自己的對話 – cwin