标签:接口 ast activity listen ret short lis turn length
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;
}
});
Adapter,Fragment向所属的activity中传值
标签:接口 ast activity listen ret short lis turn length
原文地址:http://www.cnblogs.com/princenwj/p/7222145.html