Android:通知主要活动有关自定义ListView的复选框

Android:通知主要活动有关自定义ListView的复选框,android,listview,baseadapter,android-actionmode,Android,Listview,Baseadapter,Android Actionmode,我有一个自定义的BaseAdapter显示一个列表视图,其中包含一个文本视图和一个复选框。TextView实现了一个OnClickListener,用于在单击文本时执行特定操作。在适配器中,我注册了一个OnCheckedChangeListener,它跟踪检查了哪个项目(因为ListView循环) 我想在选中复选框时启动操作模式,取消选中时停止 如何通知承载适配器的主要活动已进行检查?创建侦听器回调接口,类似于: public interface ListenerCheckBox { p

我有一个自定义的
BaseAdapter
显示一个
列表视图
,其中包含一个
文本视图
和一个
复选框
TextView
实现了一个
OnClickListener
,用于在单击文本时执行特定操作。在适配器中,我注册了一个
OnCheckedChangeListener
,它跟踪检查了哪个项目(因为
ListView
循环)

我想在选中
复选框时启动
操作模式
,取消选中时停止


如何通知承载适配器的主要活动已进行检查?

创建侦听器回调接口,类似于:

public interface ListenerCheckBox
{
    public void onRowChecked(int rowNun);
}
然后,让您的主要活动实现此侦听器:

public class ActivityMain implements ListenerCheckBox
//kv 3rd parameter would be listener
CustomBaseAdapter customBaseAdapter = new CustomBaseAdapter(this, items, this);
public CustomBaseAdapter(Context context, ArrayList<Item> items, ListenerCheckBox listenerCheckBox)
{
    mListenerCheckBox = listenerCheckBox;
    ...
}
然后,在实例化自定义BaseAdapter时,传入侦听器:

public class ActivityMain implements ListenerCheckBox
//kv 3rd parameter would be listener
CustomBaseAdapter customBaseAdapter = new CustomBaseAdapter(this, items, this);
public CustomBaseAdapter(Context context, ArrayList<Item> items, ListenerCheckBox listenerCheckBox)
{
    mListenerCheckBox = listenerCheckBox;
    ...
}
然后,在CustomBaseAdapter的构造函数中,为侦听器设置一个成员字段:

public class ActivityMain implements ListenerCheckBox
//kv 3rd parameter would be listener
CustomBaseAdapter customBaseAdapter = new CustomBaseAdapter(this, items, this);
public CustomBaseAdapter(Context context, ArrayList<Item> items, ListenerCheckBox listenerCheckBox)
{
    mListenerCheckBox = listenerCheckBox;
    ...
}
是一个Android Studio项目,它展示了如何满足您的要求。特别是,签出及其
onClick()

是一个Android Studio项目,它展示了如何满足您的要求。