如何设置复选框事件以将数据保存在recyclerview中?

时间:2019-07-16 13:28:16

标签: java android android-recyclerview recycler-adapter

我正在创建一个程序,当教师单击“缺勤”复选框时,另一活动中的“回收者”视图会显示缺席学生及其姓名和日期,我该怎么做,该复选框也处于不同的活动和“回收者”视图中

我不知道该怎么做

我的适配器:

package com.example.hozoor;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.Calendar;

public class student_adap1 extends RecyclerView.Adapter<student_adap1.studentViewHolder> {

    private Context mcontext;

    private Cursor mcusror;

    public student_adap1(Context mcontext, Cursor mcusror) {
        this.mcontext = mcontext;
        this.mcusror = mcusror;
    }
    public class studentViewHolder extends RecyclerView.ViewHolder{
        public TextView name_student;

        public studentViewHolder(@NonNull View itemView) {
            super(itemView);
            name_student=itemView.findViewById(R.id.name_ghayeb_textview);

        }
    }


    @NonNull
    @Override
    public studentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(mcontext);
        View view=inflater.inflate(R.layout.item_hazerha,parent,false);

        return new studentViewHolder(view);


    }

    @Override
    public void onBindViewHolder(@NonNull studentViewHolder holder, int position) {
        if (!mcusror.moveToPosition(position)) {
            return;
        } else {
            String name = mcusror.getString(mcusror.getColumnIndex(database_student._NAME_STUDENT));
            long id = mcusror.getLong(mcusror.getColumnIndex(database_student._ID));
            holder.name_student.setText(String.valueOf(name));
            holder.itemView.setTag(id);
        }
    }
    @Override
    public int getItemCount() {
        return mcusror.getCount();
    }
    public void swapcursor(Cursor NEWCURSOR){
        if (mcusror !=null){
            mcusror.close();
        }
        mcusror=NEWCURSOR;
        if (NEWCURSOR !=null){
            notifyDataSetChanged();
        }
    }

}

我希望回收站视图显示缺勤的学生

0 个答案:

没有答案