1

我正在创建一个应用程序,该应用程序需要 3 个以上的 Activity 对话框用于不同目的。我正在使用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();
}   

}

4

1 回答 1

1

利用

    switch(id){
         case exampleDialog_id:
             return showExapleDialog();
         break;
         case secondDialog_id:
             returnshowSecondDialog;
         break;
         default:
         return null;}
于 2013-02-15T11:14:05.397 回答