¿Cómo puedo agregar botones personalizados en un diseño de AlertDialog?
Tengo AlertDialog con botones positivos y negativos. En el diseño de AlertDialog tengo EditText y dos botones (btnAdd1, btnAdd2). Quiero que cuando el usuario haga clic en el botón btnAdd1 o btnAdd2 agregue el mismo texto a EditText en AlertDialog (pero no cierre AlertDialog). ¿Es posible hacerlo en AlertDialog o tengo que usar solo Dialog?
Este es el diseño (R.layout.prompt) de 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>
Y este es el código fuente:
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();
Quiero tener acceso a btnAdd1 y btnAdd2 desde el diseño. Establezca OnClickListener () en estos dos botones.