android - Validation on EditText from outside BaseAdapter class -
i have list box consist editbox in each row of listbox. on button save have check edittext object filled data or not.
this how constructed adapter listview:
public class lvadapter extends baseadapter { activity activity; context context; arraylist<plist> arrayplist; public lvadapter(context mcontext, arraylist<plist> array) { context = mcontext; activity = (activity) context; arrayprestart = array; } @override public int getcount() { return arrayplist.size(); } @override public object getitem(int arg0) { return arg0; } @override public long getitemid(int arg0) { return arrayplist.get(position); } @override public view getview(int position, view convertview, viewgroup arg2) { layoutinflater inflater = (layoutinflater) activity.getsystemservice(context.layout_inflater_service); final viewholder viewholder = new viewholder(); convertview = inflater.inflate(r.layout.row_prestartcheck_list, null); viewholder.edcomment = (edittext) convertview.findviewbyid(r.id.edcomment); viewholder.edcomment.settag(position); return convertview; } } public class viewholder { edittext edcomment; }
define 1 custom method in main class check empty edittext : mainclass.java:
listview lvquestion; arraylist<plist> arrayplist = new arraylist<>(); plist plist = new plist(); btnenter.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { boolean isanyempty=true; (int i=0; i<arrayplist.size(); i++) { view view = lvquestion.getadapter().getview(i, null, null); edittext quantity = (edittext) view.findviewbyid(r.id.edcomment); quantity.requestfocus(); quantity.seterror("asdasda"); isanyempty=false; break; } }); }
i have test object using settext , working fine me requestfocus , seterror not working, please figure out or give me alternate solution
you need put condition check if of edittext
empty.
change method this
public boolean isempty(){ boolean isanyempty=false; (int i=0;i<quantitychecklist.size();i++){ view view = lvquestion.getadapter().getview(i, null, null); edittext quantity = (edittext) view.findviewbyid(r.id.txtquantity); if(quantity.gettext().tostring().isempty()) { quantity.requestfocus(); quantity.seterror("asdasda"); isanyempty=true; break; } } return isanyempty; }
Comments
Post a Comment