In my XML
I set the view with 2 buttons (Cancel, Accept), and create my own class of AlertDialog
and AlertDialog.Builder
so that it is the same throughout the application.
The question is that I want my Cancel and OK button to work just like the AlertDialog.Builder.SetNegativeButton (); and the AlertDialog.Builder.SetPositiveButton (); , that when touching the button the AlertDialog is closed.
In link
It says
Discard a dialog When the user touches any of the buttons of action created with an AlertDialog.Builder, the system discards the dialogue for you.
The system also discards the dialogue when the user touches a item in a dialog list, except when the list uses buttons of selection or check boxes.
My XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gris">
<android.support.v7.widget.RecyclerView
android:id="@+id/AlertDialog_rv_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingBottom="?attr/actionBarSize"
android:layout_marginBottom="?attr/actionBarSize" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center">
<Button
android:id="@+id/AlertDialog_Negativo"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/verde"
android:text="Cancelar"
android:background="@null" />
<Button
android:id="@+id/AlertDialog_Positivo"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/verde"
android:text="Aceptar"
android:background="@null" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
My Class AlertDialog
and AlertDialog.Builder
public class myAlertDialog : AlertDialog
{
protected myAlertDialog(Context context) : base(context)
{
}
public override void Dismiss()
{
base.Dismiss();
}
public class myBuilder : Builder
{
public Context context;
private List<IListeable> list;
private Button Positivo;
private Button Negativo;
private RecyclerView RecyclerView;
private TextView Titulo;
private myAlertDialogAdapter adapter;
private Seleccion TipoSeleccion;
public myBuilder(Context context) : base(context)
{
this.context = context;
//Default seleccion Multiple
this.TipoSeleccion = Seleccion.Multiple;
//Inicializar
list = new List<IListeable>();
//Creo la vista
var view = LayoutInflater.From(context).Inflate(Resource.Layout.myAlertDialog, null, false);
RecyclerView = view.FindViewById<RecyclerView>(Resource.Id.AlertDialog_rv_data);
Positivo = view.FindViewById<Button>(Resource.Id.AlertDialog_Positivo);
Negativo = view.FindViewById<Button>(Resource.Id.AlertDialog_Negativo);
base.SetView(view);
}
public new myAlertDialog Show()
{
return base.Show() as myAlertDialog;
}
}
}
public enum Seleccion
{
Ninguno,
Simple,
Multiple
}
and if I declare it in my AppCompatActivity
myAlertDialog alert;
myAlertDialog.myBuilder builder = new myAlertDialog.myBuilder(this);
builder.SetTitle("Categorias");
//Asignar item y forma de seleccion
builder.SetItems(items, Seleccion.Multiple);
alert = builder.Show();
Could you tell me if this is possible? or some example that can help me.