0

I am trying to create a dialog box, with a title, body(message), ok -option.

How can i separate them line by line (I mean divided by lines in three parts)?

This is the code I'm using:

public void dialog_vhe(View view){
    String button_details;
    button_details = ((Button) view).getText().toString();

    AlertDialog.Builder builder2 = new AlertDialog.Builder(this);


    builder2.setMessage("   You can use either your garnt number or TRN.\n" +
            "   The Visa Grant Number can be found on your visa grant notification.\n " +
            "   The Transaction Reference Number can be found in your ImmiAccount and on any correspondence from the department. ")

            .setCancelable(false)
            .setNegativeButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

    AlertDialog alert2 = builder2.create();
    alert2.setTitle("REFERENCE NUMBER");
    alert2.show();
    setContentView(R.layout.activity_visa_holder_enquiry);
}
ItamarG3
  • 4,092
  • 6
  • 31
  • 44
  • Did you use Custom alert dialog? – Ajeet Choudhary Jun 22 '17 at 05:09
  • create a custom layout and inflate it in activity – Aashutosh Kumar Jun 22 '17 at 05:11
  • Create a string in the String.xml, I have done the same thing like below Password must contains :\n\nAt least one upper case english letter\n\nAt least one lower case english letter\n\nAt least one digit,\n\nAt least one special character (!"#$% &'()*+,-./:;>=<?@^_`{|}~)\n\nMinimum 8 in length. – Rakshit Nawani Jun 22 '17 at 05:12
  • "\n" will break the line and you can have the string in different lines – Rakshit Nawani Jun 22 '17 at 05:13
  • builder2.setMessage("You can use either your garnt number or TRN." +"\n"+ The Visa Grant Number can be found on your visa grant notification. " +"\n"+"The Transaction Reference Number can be found in your ImmiAccount and on any correspondence from the department. ").....add("\n" separate string); better to use custom dialog box.. – Gowthaman M Jun 22 '17 at 05:13
  • Thank you gowthaman,, I want to see the dividing line between title bar , the message bar and dismiss option( while clicking ok). How can get that format ,please help me i'm new to android. – Raghav Sai Jun 22 '17 at 06:15

1 Answers1

0

use custom layout of dialog and inflate it using this code

 Dialog dialog = new Dialog(MainActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.referral_code_dialog);
    dialog.setCancelable(false);
    close = (TextView) dialog.findViewById(R.id.close);
    apply = (TextView) dialog.findViewById(R.id.apply);
    error = (TextView) dialog.findViewById(R.id.error);
    referral = (EditText) dialog.findViewById(R.id.referral_code);
    dialog.show();

    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    apply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
Aashutosh Kumar
  • 183
  • 4
  • 12