0
I wanted to change the buttons of my Alertdialog for example: I would like to exchange the positivebutton for a textview and so put the onClick event in it.
My java:
Mainactivity.java
public void onBackPressed() {
View view = this.getLayoutInflater().inflate(R.layout.dialogo_multiuso, null);
((TextView)view.findViewById(R.id.botao_negativo)).setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
}
});
((TextView)view.findViewById(R.id.botao_positivo)).setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
MenuActivity.this.finish();
}
});
if (this.conf.getString("tema", "").equals((Object)"claro")) {
((LinearLayout)view.findViewById(R.id.fundo)).setBackgroundColor(-4342339);
((TextView)view.findViewById(R.id.titulo)).setTextColor(-16777216);
((TextView)view.findViewById(R.id.titulo)).setBackgroundColor(-6381922);
((TextView)view.findViewById(R.id.texto)).setTextColor(-16777216);
((TextView)view.findViewById(R.id.texto)).setBackgroundColor(-6381922);
((TextView)view.findViewById(R.id.botao_positivo)).setTextColor(-16777216);
((TextView)view.findViewById(R.id.botao_negativo)).setTextColor(-16777216);
((LinearLayout)view.findViewById(R.id.fundo_opcoes)).setBackgroundColor(-6381922);
}
if (this.conf.getString("idioma", "").equals((Object)"pt")) {
AlertDialog.Builder builder = new AlertDialog.Builder((Context)this);
((TextView)view.findViewById(R.id.titulo)).setText((CharSequence)"Quer realmemte sair?");
((TextView)view.findViewById(R.id.botao_positivo)).setText((CharSequence)"Sim");
((TextView)view.findViewById(R.id.botao_negativo)).setText((CharSequence)"N\u00e3o");
((TextView)view.findViewById(R.id.texto)).setVisibility(8);
builder.setView(view);
builder.create().show();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder((Context)this);
((TextView)view.findViewById(R.id.titulo)).setText((CharSequence)"Do you really want to leave?");
((TextView)view.findViewById(R.id.botao_positivo)).setText((CharSequence)"Yes");
((TextView)view.findViewById(R.id.botao_negativo)).setText((CharSequence)"No");
((TextView)view.findViewById(R.id.texto)).setVisibility(8);
builder.setView(view);
builder.create().show();
}
My XML is: xml dialog.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="1" android:layout_width="-1" android:layout_height="-2">
<LinearLayout android:orientation="1" android:id="false" android:background="424242" android:padding="10dp" android:layout_width="-1" android:layout_height="-2">
<TextView android:textSize="16sp" android:textStyle="1" android:textColor="ffffff" android:gravity="16" android:id="false" android:background="000" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="50dp" android:text="Titulo" />
<TextView android:textSize="14sp" android:textStyle="1" android:textColor="ffffff" android:gravity="51" android:id="false" android:background="000" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="-2" android:layout_marginTop="5dp" android:text="Texto do diálogo." />
<LinearLayout android:orientation="0" android:id="false" android:background="000" android:layout_width="-1" android:layout_height="40dp" android:layout_marginTop="5dp">
<TextView android:textSize="16sp" android:textStyle="1" android:textColor="ffffff" android:gravity="17" android:id="false" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="-1" android:text="não" android:layout_weight="{4:1065353216}" />
<TextView android:textSize="16sp" android:textStyle="1" android:textColor="ffffff" android:gravity="17" android:id="false" android:padding="10dp" android:focusable="false" android:layout_width="-1" android:layout_height="-1" android:text="sim" android:layout_weight="{4:1065353216}" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This is all I need for my Alertdialog to be complete. If anyone wants more information, please do not hesitate to ask for my thanks.
What’s the problem with the code? Where it doesn’t work as expected?
– ramaral
You can make an xml with textview and inflate inside alertdialog
– Costamilam
@ramaral my doubt is how I can use the Inflater so that when I click on a text view it has the same effect as a negativeButton for example.
– AndronCreation
The click on
textView R.id.botao
_positive is working?– ramaral
Yes the positive and to end the application only the negative that no, in case I’m trying to close the dialog box when it is clicked but I’m not getting.
– AndronCreation