Add resume / additional text in alertDialog for individual selection items

Is there a way to add a bulletin or additional text to alertDialog with elements of one choice? I would like to have a bold headline and short text with additional information.

+4
source share
4 answers

Google says:

"Because the list is displayed in the content area of ​​the dialog box, the dialog box cannot display both the message and the list": http://developer.android.com/guide/topics/ui/dialogs.html

, , . , , - DialogFragment

+2

, :

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                context);

            // set title
            alertDialogBuilder.setTitle("Your Title");

            // set dialog message
            alertDialogBuilder
                .setMessage("Click yes to exit!")
                .setCancelable(false)
                .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, close
                        // current activity
                        MainActivity.this.finish();
                    }
                  })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });

                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            }
-1

setSingleChoiceItems AlertDialog -

final CharSequence[] items = {"Red", "Green", "Blue"};

AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(10); //small text font
dialog.setTitle("Colors");
dialog.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int item) {
                Toast.makeText(getApplicationContext(), 
items[item], Toast.LENGTH_SHORT).show();
     }
 });
-1

- :

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
builder.setMessage("Message");
builder.setPositiveButton("OK", null);
AlertDialog dialog = builder.show();

// Must call show() prior to fetching text view
TextView messageView = (TextView)dialog.findViewById(android.R.id.message);
messageView.setGravity(Gravity.CENTER);

: fooobar.com/questions/98680/...

-1

Source: https://habr.com/ru/post/1547442/


All Articles