复选框界面和recyclerview适配器出错

我有一个RecyclerView,它显示任务并包含复选框。当用户单击复选框时,我要检查任务的结束时间是否小于当前时间,如果为true,则该复选框将保持选中状态,否则应取消选中该复选框。让我借助代码来阐明我的问题。

在我的适配器中,我创建了一个接口:

private OnItemClickedListener listener;

public void setOnItemClickedListener(OnItemClickedListener listener){
    this.listener = listener;
}
interface OnItemClickedListener {
    void onItemClick(View v, int position, boolean isChecked, int time);
}

然后,在OnBindViewHolder中,将onClickListener设置为复选框:

@Override
public void onBindViewHolder(@NonNull final SortedViewHolder holder, final int position) {
    final Sorted data = list.get(position);
    holder.title.setText(data.getSortedName());
    holder.date.setText(data.getSortedDate());
    holder.category.setText(String.valueOf(data.getSortedCategory()));
    holder.attach.setText(String.valueOf(data.isSortedAttach()));
    holder.to.setText(String.valueOf(toTime(data.getSortedDuration() + data.getSortedTimeBegin())));
    holder.from.setText(String.valueOf(toTime(data.getSortedTimeBegin())));
    holder.checkBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listener != null){
                boolean isChecked = holder.checkBox.isChecked();
                listener.onItemClick(v, position, isChecked, data.getSortedDuration() + data.getSortedTimeBegin());
            }
        }
    });
}

(注意:我以分钟为单位存储任务的时间,因此以后我将它们分别分为几分钟和几小时)。

之后,在我的活动中,我得到此方法并检查时间:

//in OnCreate: 
final SortedAdapter adapter = new SortedAdapter();
adapter.setOnItemClickedListener(this);

@Override
public void onItemClick(View v, int position, boolean isChecked, int time) {
    if (isChecked){
        //String currentTime = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(new Date());
        //get current day time
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        int minute = Calendar.getInstance().get(Calendar.MINUTE);
        //compare to the given
        if (hour > time/60){
            //save state
            Toast.makeText(this, "check1", Toast.LENGTH_SHORT).show();
        }
        else if (hour == time/60){
            if (minute > time % 60){
                //save state
                Toast.makeText(this, "check2", Toast.LENGTH_SHORT).show();
            }
            else{
                //set the checkbox to false
                Toast.makeText(this, "uncheck1", Toast.LENGTH_SHORT).show();
                listener.onCheckBoxOff(v);
            }
        }
        else{
            Toast.makeText(this, "uncheck2", Toast.LENGTH_SHORT).show();
            listener.onCheckBoxOff(v);
        }
    }
}

所有的吐司都很好。现在,我想以某种方式访问​​我的复选框变量并更改其状态。这是我的问题。我真的不明白该怎么做。 我尝试在活动中创建另一个界面:

 //outside activity class
 interface CheckBoxOff {
    void onCheckBoxOff(View v);
 }

//in activity class before onCreate
private CheckBoxOff listener;

void setCheckboxOffListener(CheckBoxOff listener){
    this.listener = listener;
}

因此,我在适配器中实现了它:

@Override
public void onCheckBoxOff(View v) {
    SortedViewHolder holder = new SortedViewHolder(v);
    holder.checkBox.setChecked(false);
}

然后我在BindViewHolder中写了(也许这是错误的?):

ShowSortedActivity activity = new ShowSortedActivity();
activity.setCheckboxOffListener(this);

启动我的应用程序后,出现错误:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.example.tryalgorithm.ui.CheckBoxOff.onCheckBoxOff(android.view.View)' on a null object reference
    at com.example.tryalgorithm.ui.ShowSortedActivity.onItemClick(ShowSortedActivity.java:104)
    at com.example.tryalgorithm.ui.SortedAdapter$1.onClick(SortedAdapter.java:66)
    at android.view.View.performClick(View.java:6304)
    at android.widget.CompoundButton.performClick(CompoundButton.java:134)
    at android.view.View$PerformClick.run(View.java:24803)
    at android.os.Handler.handleCallback(Handler.java:794)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:6635)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

您能解释一下我在做什么错吗?也许还有另一种方法可以将复选框设置为false,而不是借助界面,还是这种方法很好?谢谢你的帮助。