How to limit number of lines in Dynamic Android EditText within AlertDialog -
i dynamically creating edittext within alertdialog , want limit number of lines shown. currently, edittext keeps expanding vertically each carriage return. results in dialog buttons not being visible after point. have isolated code down following :
public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button b = (button) findviewbyid(r.id.button); b.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { alertdialog.builder builder = new alertdialog.builder(v.getcontext()); edittext input = new edittext(v.getcontext()); input.setlines(4); //input.setmaxlines(4); input.setsingleline(false); input.setgravity(gravity.top); //input.setverticalscrollbarenabled(true); builder.setview(input); builder.setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }); builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }); alertdialog d = builder.create(); d.show(); } }); }
}
i'd happy either a) limit number of lines of text or b) have scrollbar appear beyond x lines.
i've tried setting number of properties on edittext including 'setmaxlines','setheight' , 'setverticalscrollbarenabled' , neither of these work.
i realise there existing suggestions similar issues, none edittext created dynamically , within alertdialog. or suggestions appreciated.
if want set fixed number of lines should do
setlines(int numoflines);
if want set limit number of lines added on typing
setmaxlines(int limit);
and additional information, set limit minimum number of lines using
setminlines(int limit);
Comments
Post a Comment