Home Ask Login Register

Developers Planet

Your answer is one click away!

Abe February 2016

Validation on EditText from outside BaseAdapter class

I have list box that consist EditBox in each row of listbox. On button Save I have to check is all EditText object filled with data or not.

This is how is constructed adapter for 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;

    public int getCount() {
        return arrayPList.size();

    public Object getItem(int arg0) {
        return arg0;

    public long getItemId(int arg0) {
        return arrayPList.get(position);

    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);
        return convertView;

public class ViewHolder {
        EditText edComment;

Define one custom method in main class to check for any empty EditText : MainClass.java:

ListView lvQuestion;
ArrayList<PList> arrayPList = new ArrayList<>();
PList pList = new PList();
btnEnter.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            boolean isAnyEmpty=true;
            for (int i=0; i<arrayPList.size(); i++) {
                 View view =  lvQuestion.getAdapter().getView(i, null, null);
                 EditText quantity = (EditText) view.findViewById(R.id.edComment);


Rohit5k2 February 2016

You need to put a condition to check if any of the EditText is empty.

Change your method like this

public boolean isEmpty(){
    boolean isAnyEmpty=false;
    for (int i=0;i<quantityCheckList.size();i++){
        View view =  lvQuestion.getAdapter().getView(i, null, null);
        EditText quantity = (EditText) view.findViewById(R.id.txtQuantity);
   return isAnyEmpty;

Post Status

Asked in February 2016
Viewed 2,721 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life