Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AlertDialog multiline EditText

Is there a way to create a multiline EditText in a AlertDialog in Android. I set the setLines and it shows a bigger EditText for several lines. but when I'm typing it doesn't go to next line and still types in the same line. Here is my code.

Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Comment");

        final EditText input = new EditText(this);

        final String item_value = ItemList.get(position).get("comment");

        input.setText(item_value);
        input.setInputType(InputType.TYPE_CLASS_TEXT);
        input.setLines(5);
        input.setMaxLines(5);
        input.setGravity(Gravity.LEFT | Gravity.TOP);
        builder.setView(input);

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {


            }
        });

        builder.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();

and my dialog looks like this.enter image description here

so how can I fix this. Thanks and regards.

like image 298
Samantha Withanage Avatar asked Feb 20 '17 07:02

Samantha Withanage


1 Answers

try this code for your EditText:

input.setSingleLine(false);  //add this
input.setLines(4);
input.setMaxLines(5);
input.setGravity(Gravity.LEFT | Gravity.TOP);
input.setHorizontalScrollBarEnabled(false); //this
like image 99
rafsanahmad007 Avatar answered Oct 11 '22 13:10

rafsanahmad007