I have ListView
, populating rows using adapter class. In row i have EditText
. Now when i click submit button in activity, i need to check all rows edit texts for empty. If any EditText
is empty i want to display toast message. How to achieve this. small code snippet need.
Asked
Active
Viewed 1,118 times
0

Linh
- 57,942
- 23
- 262
- 279
-
1Please share your small code snippet of what you have tried. We can help you in adding code to that. – bozzmob Dec 24 '15 at 07:40
-
Just check the edittext data lenght of corresponding position. – Anuj Sharma Dec 24 '15 at 08:57
4 Answers
2
I think the simplest way is
- You store the data in the EditText
whenever user input data into an Object
or List
- Then when Submit Button
is clicked, just need to check the Object
is null or not
Or
You can find each item (row) in ListView
by position
public View getViewByPosition(int pos, ListView listView) {
final int firstListItemPosition = listView.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
if (pos < firstListItemPosition || pos > lastListItemPosition ) {
return listView.getAdapter().getView(pos, null, listView);
} else {
final int childIndex = pos - firstListItemPosition;
return listView.getChildAt(childIndex);
}
}
Then find the EditText
in each row
EditText editText = getViewByPosition(pos,listView).findViewById(R.id.editext_id);
Finally check it empty or not
if(editText.getText().length == 0){
// EditText is empty, display toast here
Toast.makeText("","");
}
Hope this help

Linh
- 57,942
- 23
- 262
- 279
1
Something like this
EditText usernameEditText = (EditText) findViewById(R.id.editUsername);
sUsername = usernameEditText.getText().toString();
if (sUsername.matches("")) {
Toast.makeText(this, "You did not enter a username", Toast.LENGTH_SHORT).show();
return;
}
This is an example. Of course, you need to get this EditText from your row first.

RexSplode
- 1,475
- 1
- 16
- 24
0
Loop through the items of the listview, get the TextView by id from the listview item and check the length of its text
You can get the listview item like the following Link
for(int i = 0; i<listview.getCount(); i++){
TextView tv = ((View)listview.getViewByPosition(i, listview)).findViewById(R.id.textView);
if(tv.getText().toString().length() == 0){
tv.setError("This is required");
}
}

Community
- 1
- 1

Malek Hijazi
- 4,112
- 1
- 26
- 31
0
This will help you for what you want it will check the empty cell of list:
private int checkForEditText() {
for (int i = 0; i < yourListSize; i++) {
if (TextUtils.isEmpty(youlistSize.get(i))) {
//return positin of empty cell
return i;
}
}
//if no cell is empty it retur -1
return -1;
}

santoXme
- 802
- 5
- 20