2 つの EditText を含むレイアウトを作成し、それを で膨らませて、それをLayoutInflater
のビューとして使用できますAlertDialog
。
LayoutInflater factory = LayoutInflater.from(this);
//text_entry is an Layout XML file containing two text field to display in alert dialog
final View textEntryView = factory.inflate(R.layout.text_entry, null);
final EditText input1 = (EditText) textEntryView.findViewById(R.id.EditText1);
final EditText input2 = (EditText) textEntryView.findViewById(R.id.EditText2);
input1.setText("DefaultValue", TextView.BufferType.EDITABLE);
input2.setText("DefaultValue", TextView.BufferType.EDITABLE);
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setIcon(R.drawable.icon).setTitle("EntertheText:").setView(textEntryView).setPositiveButton("Save",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
Log.i("AlertDialog","TextEntry 1 Entered "+input1.getText().toString());
Log.i("AlertDialog","TextEntry 2 Entered "+input2.getText().toString());
/* User clicked OK so do some stuff */
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
/*
* User clicked cancel so do some stuff
*/
}
});
alert.show();
次のように、プログラムで EditText を追加することもできます。
LinearLayout layout = new LinearLayout(mapView.getContext());
layout.setOrientation(LinearLayout.VERTICAL);
final EditText titleBox = new EditText(mapView.getContext());
titleBox.setHint("Title");
layout.addView(titleBox);
final EditText descriptionBox = new EditText(mapView.getContext());
descriptionBox.setHint("Description");
layout.addView(descriptionBox);
dialog.setView(layout);