适配器里写代码
**有参构造上方写**
/*点击rv的item跳转*/
OnItemClickListener listener;
public interface OnItemClickListener{
/*注意参数*/
public void OnItemClick(View v,int position,String id);
}
public void setOnItemClick(OnItemClickListener listener){
this.listener=listener;
}
**onBindViewHolder里写**
/*点击rv的item跳转*/
myViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(listener!=null){
/*注意参数*/
listener.OnItemClick(v,position,bnlist.get(position).getDataId());
}
}
});
MainActivity里写代码
**配置适配器下写**
/*点击rv的item跳转*/
myadapter.setOnItemClick(new Myadapter.OnItemClickListener() {
@Override
public void OnItemClick(View v, int position, String id) {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
/*传ID在Main2Activity接受*/
/* intent.putExtra("id",id);*/
startActivity(intent);
}
});
Main2Activity接受传来的值
/*接收MainActivity传来的ID*/
/* Intent intent=getIntent();
String id=intent.getStringExtra("id");*/