How to fix the buttons in Alertdialog?

Asked

Viewed 145 times

1

I’m having a problem with the buttons created in Alertdialog. I am making a phrase APP and at certain times the sentences are very large and causes the buttons in Alertdialog to drop. Is it possible to fix these buttons? Here follows an example of what happens: http://www.mediafire.com/view/ykk010cb8jcb6v5/Screenshot_20170607-111014.png

This is my code:

// ALERT DIALOG


                    //atributo da classe.

                    //Cria o gerador do AlertDialog
                    AlertDialog.Builder builder = new AlertDialog.Builder(FraseAutorFrase.this);
                    builder.setTitle("O que deseja fazer?");//define o titulo
                    builder.setMessage("\nFrase: " + frasesR [position]);//define a mensagem
                    builder.setView(checkBoxView);

                    //define um botão como positivo
                    builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {

                        }
                    });

                    //define um botão como compartilhar
                    builder.setPositiveButton("Compartilhar", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {

                            Intent sendIntent = new Intent();
                            sendIntent.setAction(Intent.ACTION_SEND);
                            sendIntent.putExtra(Intent.EXTRA_TEXT, frasesR[position] );
                            sendIntent.setType("text/plain");
                            startActivity(sendIntent);
                        }
                    });

                    alerta = builder.create();//cria o AlertDialog
                    alerta.show();//Exibe

Thank you very much!!!

  • 1

    Why don’t you create a scroll in the phrase?

  • Try entering your code to your question. This increases the chance that you have a more accurate answer.

  • Hi, Luiz. I wouldn’t know how to implement Scroll, I actually saw an alternative that would have to change the layout, but I’ll try.

  • Thank you, Aclay.

1 answer

2


You can build a custom layout and put a Scrollview inside it

messagem_dialog.xml

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/mensagem"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="" />

    </LinearLayout>
</ScrollView>

and then in your Activity you "inflate" this layout and insert in the dialog

LayoutInflater inflater= LayoutInflater.from(this);
View view=inflater.inflate(R.layout.mensagem_dialog, null);

TextView textview=(TextView)view.findViewById(R.id.mensagem);
textview.setText("\nFrase: " + frasesR [position]);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);  
alertDialog.setTitle("O que deseja fazer?");  
alertDialog.setView(view);
alertDialog.setButton("OK", null);  
AlertDialog alert = alertDialog.create();
alert.show();

You can adapt the layout and insert the checkbox to contemplate the favorites, the cool that you will have full control of the layout :D

  • Hello, Milton. Thank you very much for the reply. I haven’t tested the code yet, but saw that declared a Textview, in my code does not have Textview, it already takes the information of an Array by setMessage. This code only works with Textview? Thanks.

  • In fact the textview ta in this other layout messagem_dialog that you inflate and inject in Alertdialog, yes you will have a textview to display your message

  • Thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.