I have AlertDialog with Positive and Negative buttons. In AlertDialog layout I have EditText and two Buttons (btnAdd1, btnAdd2). I want when user click at the Button btnAdd1 or btnAdd2 add same text to EditText in AlertDialog (but no close AlertDialog). Is this possible do in AlertDialog or I have to use only Dialog?
This is layout (R.layout.prompt) of AlertDialog:
<LinearLayout>
<EditText
android:id="@+id/userInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="@+id/btnAdd1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bla" />
<Button
android:id="@+id/btnAdd2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bla" />
</LinearLayout>
And this is source code:
LayoutInflater layoutInflater = LayoutInflater.from(this);
View promptView = layoutInflater.inflate(R.layout.prompt, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(promptView);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//...
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertD = alertDialogBuilder.create();
alertD.show();
I want get acces to the btnAdd1 and btnAdd2 from the layout. Set the OnClickListener() to these two buttons.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…