I have a Listview
of custom adapter
which has five fields in it.
Name
, Cnic
, No
, Desgination
and attendance
. Now what i want to do is that i have to check whether all the list items have some value written after attendance column
. If there is any thing on attendance column
then the user can move to next activity
otherwise it will prompt user to mark attendance.
Here is my code for getting value and setting in the adapter
.
for (int p = 0; p < teacherList.size(); p++) {
details = new DetailsTeacherwebservice();
//ArrayList<Object> baris = data.get(p);
details.setId(teacherList.get(p).getId());
details.setTeachername(teacherList.get(p).getTeachername());
details.setTeachercnic(teacherList.get(p).getTeachercnic());
details.setTeacherno(teacherList.get(p).getTeacherno());
details.setTeachergender(teacherList.get(p).getTeachergender());
details.setAttendance(teacherList.get(p).getAttendance());
addas.add(details);
}
cusadapter = new CustomAdapterTeacherWebservice(TeacherWebserviceMainList.this, addas);
listcontent.setAdapter(cusadapter);
Here is the code for moving to next activity
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent view_order_intent = new Intent(TeacherList.this, M_TeacherPresenceList.class);
startActivity(view_order_intent);
finish();
}
});
User can not move to next activity
if attendance
is empty
or Null
so that user has to mark attendance for all teachers in the list and then can go to next.
Please Help
Try this
ArrayList<Boolean> isAllMarked = new ArrayList<>();
int attentednceMarkedCount = 0;
for (int p = 0; p < teacherList.size(); p++) {
if (!TextUtils.isEmpty(teacherList.get(p).getAttendance())) {
isAllMarked.add(true);
} else {
isAllMarked.add(false);
}
}
for (int i = 0; i < isAllMarked.size(); i++) {
if (isAllMarked.get(i)) { //if marked true
attentednceMarkedCount = attentednceMarkedCount + 1;
}
}
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (attentednceMarkedCount ==teacherList.size()) {
Intent view_order_intent = new Intent(TeacherList.this, M_TeacherPresenceList.class);
startActivity(view_order_intent);
finish();
} else {
showAlert()
}
}
});