检查listview项是否包含指定数据,然后启动下一个活动

时间:2018-01-01 06:10:25

标签: android listview custom-adapter

我有一个Listview custom adapter,其中有五个字段。 NameCnicNoDesginationattendance。现在我要做的是我必须检查所有列表项是否在attendance column之后写了一些值。如果attendance column上有任何内容,则用户可以移至下一个activity,否则会提示用户标记出勤。

以下是我在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);

以下是移至下一个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();
        }
    });

如果activityattendanceempty,则用户无法移至下一个Null,因此用户必须为列表中的所有教师标记出勤率,然后才能转到下一个。 请帮忙

4 个答案:

答案 0 :(得分:1)

编写一个返回布尔值的方法来检查是否缺少任何一个考勤,当找到缺少的考勤时,立即退出循环以使attendanceStatus准确。

private boolean hasAllAttendance(){
    boolean attendanceStatus= true;

 for (int p = 0; p < teacherList.size(); p++) {
    details = new DetailsTeacherwebservice();

    if(teacherList.get(p).getAttendance() == null || 
           teacherList.get(p).getAttendance().equal("") ){
        attendanceStatus = false;
        break;
    }
  return attendanceStatus;
}

现在,使用此方法,控制您的活动转换或祝酒消息

next.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

    if(hasAllAttendance()){           
        Intent view_order_intent = new 
        Intent(TeacherList.this, M_TeacherPresenceList.class);
        startActivity(view_order_intent);
        finish();
    } else //Toast message

  }
});

答案 1 :(得分:1)

试试这个

    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()
            }

        }
    });

答案 2 :(得分:0)

//试试这个

/assets/glyphicons-halflings-regular.wof

答案 3 :(得分:0)

使用next.setOnClickListener(new View.OnClickListener() getView() Adapter方法private boolean checkAttendance(){ boolean hasAll = true; for (int i = 0; i < teacherList.size(); i++) { if(att.empty() || att == null){ hasAll = false; break; } return hasAll ; } 。喜欢 -

getView()

on next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(checkAttendance()){ Intent view_order_intent = new Intent(TeacherList.this, M_TeacherPresenceList.class); startActivity(view_order_intent); finish(); }else{ showYourCustomAlert() // your alert dialog } } }); 方法 -

r.getInt(1);