一.创建接口或内部接口
public interface TwoFragmentInterface{
void onListener(String id);
}
二.在Adapter
1.设置全局变量
private TwoFragmentInterface twoFragmentInterface;
2.添加set方法
public void setTwoFragmentInterface(TwoFragmentInterface twoFragmentInterface) {
this.twoFragmentInterface = twoFragmentInterface;
}
3.在onBindViewHolder方法中使用
helper.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
twoFragmentInterface.onListener(item.getReqStartTime());
}
});
三.在Activity
(实现接口和方法)
1.实现接口
public class TwoFragment extends BaseFragment implements TwoFragmentRecyclerViewAdapter.TwoFragmentInterface {

2.添加set方法
twoFragmentRecyclerViewAdapter.setTwoFragmentInterface(this);

3.实现中的点击方法
@Override
public void onListener(String id) {
Log.e(TAG, "onListener: "+id );
}
网友评论