1、在adapter或fragment中定义接口
如:
public interface LongClickListener {
void getClickName(String name);
}
然后在需要触发该接口方法中添加
如:
holder.img_avatar.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
String ClickName = datas.get(position).getToUserName();
Toast.makeText(cxt, "长按点击事件"+ClickName,Toast.LENGTH_SHORT).show();
if (cxt instanceof LongClickListener){
((LongClickListener) cxt).getClickName(ClickName); //这两行是关键
}
return false;
}
});
时间: 2024-10-11 18:50:41