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.
so how can I fix this. Thanks and regards.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With