ユーザーが新しいアイテムを追加したいときに呼び出されるリスナーがあります。リスナーは、このフォームで 2 つの EditText を含む AlertDialog を表示する必要があります。
-AlertDialog Title
-AlertDialog Message
-TextView 1 above EditText1
-EditText1
-TextView 2 above EditText2
-EditText 2
2 つのボタン
-*Cancel* on the left
-*Add* on the right
私のコードは
OnClickListener addNewItemListener = new OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
MyActivity.this);
alert.setTitle(R.string.add_title);
alert.setMessage(R.string.add_message);
final TextView t1 = new TextView(MyActivity.this);
t1.setText("Name");
final EditText input1 = new EditText(MyActivity.this);
final TextView t2 = new TextView(MyActivity.this);
t2.setText("Value");
final EditText input2 = new EditText(MyActivity.this);
alert.setView(t1);
alert.setView(input1);
alert.setView(t2);
alert.setView(input2);
alert.setPositiveButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alert.setNegativeButton(R.string.add,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
try {
String name = input1.getText().toString();
double value = Double.parseDouble(input2
.getText().toString());
addItem(name, value);
} catch (RuntimeException e) {
Alerts.DatiErrati(MyActivity.this);
}
}
});
alert.show();
}
};
残念ながら、当初の意図にもかかわらず、EditTextと2つのボタンしかないAlertDialogが表示されます
どうすればこれを修正できますか?