2016-04-12 22 views
-1

ここで私は学校の出席に取り組んでいます(listviewの最初の項目をクリックしたときに、すべての不在またはすべてをマークします)リストビューの外にあるボタンを使用していますが、ボタンなしのリストビューの最初の項目で必要です。あなたのonItemClick法でandroidのlistviewの最初の項目をクリックしてlistviewの項目を変更する方法

public class StudentsAttendanceActivity extends AppCompatActivity implements AsyncResponse, SwipeRefreshLayout.OnRefreshListener { 


    public StudentsAttendanceAdapter mAttendanceAdapter; 
    public ArrayList<StudentsAttendenceModel> mListInfo = new ArrayList<>(); 
    int index, mTop,mEmployeeId; 
    View mRootView; 

    public int classId; 
    //private SwipeRefreshLayout swipeLayout; 
    private ListView mListView; 
    String className; 
    String classIdNo; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.students_attendance_layout); 

     //mRootView = inflater.inflate(R.layout.students_attendance_layout, false); 
     //swipeLayout=(SwipeRefreshLayout) mRootView.findViewById(R.id.swipe_container); 
     mListView = (ListView) findViewById(R.id.studentsList); 
     final Button allStudentSelectionButton = (Button) findViewById(R.id.allStudentSelectionButton); 
     allStudentSelectionButton.setTag("Present"); 
     //ListView mEmpty = (ListView) mRootView.findViewById(R.id.studentsList); 

     StudentsAttendenceModel studentsAttendenceModel1=new StudentsAttendenceModel(); 
     studentsAttendenceModel1.setStudentId("001"); 
     studentsAttendenceModel1.setStudentRollNumber("1"); 
     studentsAttendenceModel1.setStudentName("Anurag Thakur"); 
     studentsAttendenceModel1.setStudentAttendenceStatus("Present"); 
     studentsAttendenceModel1.setClassName("5th A"); 
     mListInfo.add(studentsAttendenceModel1); 

     StudentsAttendenceModel studentsAttendenceModel2=new StudentsAttendenceModel(); 
     studentsAttendenceModel2.setStudentId("002"); 
     studentsAttendenceModel2.setStudentRollNumber("2"); 
     studentsAttendenceModel2.setStudentName("Funsukh Wangadu"); 
     studentsAttendenceModel2.setStudentAttendenceStatus("Present"); 
     studentsAttendenceModel2.setClassName("5th A"); 
     mListInfo.add(studentsAttendenceModel2); 

     StudentsAttendenceModel studentsAttendenceModel3=new StudentsAttendenceModel(); 
     studentsAttendenceModel3.setStudentId("003"); 
     studentsAttendenceModel3.setStudentRollNumber("3"); 
     studentsAttendenceModel3.setStudentName("Chatur Lingam"); 
     studentsAttendenceModel3.setStudentAttendenceStatus("Present"); 
     studentsAttendenceModel3.setClassName("5th A"); 
     mListInfo.add(studentsAttendenceModel3); 

     StudentsAttendenceModel studentsAttendenceModel4=new StudentsAttendenceModel(); 
     studentsAttendenceModel4.setStudentId("004"); 
     studentsAttendenceModel4.setStudentRollNumber("4"); 
     studentsAttendenceModel4.setStudentName("Virusahastra Budhi"); 
     studentsAttendenceModel4.setStudentAttendenceStatus("Present"); 
     studentsAttendenceModel4.setClassName("5th A"); 
     mListInfo.add(studentsAttendenceModel4); 

     mAttendanceAdapter = new StudentsAttendanceAdapter(mListInfo,this); 
     mListView.setAdapter(mAttendanceAdapter); 
     mListView.setSelectionFromTop(index, mTop); 
     //mListView.setEmptyView((TextView) mRootView.findViewById(R.id.studentName)); 

     /*mAdapter = new ClassStudentsRecyclerAdapter(results,getContext()); 
     mRecyclerView.setAdapter(mAdapter);*/ 

     //swipeLayout.setOnRefreshListener(this); 
     SharedPreferenceSingleton.getInstance().init(getApplicationContext()); 
     className = SharedPreferenceSingleton.getInstance().getStringPreference(TeacherPreference.CLASS_NAME); 

     SharedPreferenceSingleton.getInstance().init(getApplicationContext()); 
     classIdNo = SharedPreferenceSingleton.getInstance().getStringPreference(SharedContracts.CLASS_LIST_INFO + className); 


     allStudentSelectionButton.setOnClickListener(new OnClickListener() 
     { 
      @Override 

      public void onClick(View v) 
      { 
       String status=(String) v.getTag(); 
       if (status=="Present") 
       { 
        allStudentSelectionButton.setText("Make All Late"); 
        allStudentSelectionButton.setTag("Absent"); 

        for (int i=0;i<mListInfo.size();i++) 
        { 
        mListInfo.get(i).setStudentAttendenceStatus("Absent"); 
        } 
       } 
       else if (status=="Absent") 
       { 
        allStudentSelectionButton.setText("Make All Present"); 
        allStudentSelectionButton.setTag("Late"); 

        for (int i=0;i<mListInfo.size();i++) 
        { 
         mListInfo.get(i).setStudentAttendenceStatus("Late"); 
         // ImageView attendanceStatus=(ImageView) mRootView.findViewById(R.id.attendenceStatusImage); 
        } 
       } 
       else if(status=="Late") 
       { 
        allStudentSelectionButton.setText("Make All Absent"); 
        allStudentSelectionButton.setTag("Present"); 

        for (int i=0;i<mListInfo.size();i++) 
        { 
         mListInfo.get(i).setStudentAttendenceStatus("Present"); 
         // ImageView attendanceStatus=(ImageView) mRootView.findViewById(R.id.attendenceStatusImage); 
        } 
       } 
       mAttendanceAdapter.notifyDataSetChanged(); 
      } 
     }); 
     mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() 
     { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
      { 
       String status=mListInfo.get(position).getStudentAttendenceStatus(); 
       if (status=="Present") 
       { 
        mListInfo.get(position).setStudentAttendenceStatus("Absent"); 

       } 
       else if (status=="Absent") 
       { 
        mListInfo.get(position).setStudentAttendenceStatus("Late"); 
       } 
       else if(status=="Late") 
       { 
         mListInfo.get(position).setStudentAttendenceStatus("Present"); 
       } 
       mAttendanceAdapter.notifyDataSetChanged(); 
      } 
     }); 
    } 
+0

はあなたのアダプタと、リスト項目のレイアウトを投稿する場合は存在しないか、または現在マークするために実装を変更。あなたはチェックボックスを使っていますか? –

答えて

関連する問題