0
我正在創建一個應用程序,該活動需要超過3個對話框用於不同的目的。我正在使用onCreateDialog()
方法,它目前正在處理一個在XML
文件中定義的單個對話框,我需要知道的是如何在不使我的代碼大的情況下處理更多的xml文件。如何在同一活動中處理多個對話框
@Override
protected Dialog onCreateDialog(int id){
return createExampleDialog(); // Function call, body is defined below
}
// This method is used for setting the dialogbox
@Override
protected void onPrepareDialog(int id,Dialog loginPrompt){
final EditText first = (EditText)loginPrompt.findViewById(R.id.rf1);
first.setText(""); // setting the editbox blank
final EditText second = (EditText)loginPrompt.findViewById(R.id.rf2);
second.setText("");
}
//Body the function createExampleDialog()
private Dialog createExampleDialog(){
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.userpasslayout, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Add Location!");
alert.setIcon(R.drawable.logo);
alert.setMessage("Fill information carefully!");
alert.setView(textEntryView);
//AlertDialog loginPrompt = alert.create();
//PositiveButton Onclick Listener
alert.setPositiveButton("Register", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(DialogActivity.this, "So you think!", Toast.LENGTH_LONG).show();
return;
}
});
//NegativeButton onclick Listener
alert.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
// NegtiveButton works automatic it will perform cancel of the dialog box;
return;
}
});
return alert.create();
}
}
裏面一個對話框ü要處理基於您的呼叫不同的個XML? – moDev 2013-02-15 11:55:35