我創建了一個名單,我想實現一個clickListener 但點擊沒有捕獲的問題Recyclerview點擊
public static class MyViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
public TextView design, ip, port, number, id;
public MyViewHolder(View view) {
super(view);
view.setOnClickListener(this);
design = (TextView) view.findViewById(R.id.txt_device_designation);
port = (TextView) view.findViewById(R.id.txt_device_port);
ip = (TextView) view.findViewById(R.id.txt_device_ip);
number = (TextView) view.findViewById(R.id.txt_device_number);
id = (TextView) view.findViewById(R.id.txt_device_id);
}
@Override
public void onClick(View v) {
Log.i("Test", "Test");
}
}
現在我想,如果我點擊菜單圖標,我希望有一個菜單,會出現底部 我設法按鈕和位置的點擊,但你能不能幫我調出菜單
public MyViewHolder(View view) {
super(view);
view.setOnClickListener(this);
design = (TextView) view.findViewById(R.id.txt_device_designation);
port = (TextView) view.findViewById(R.id.txt_device_port);
ip = (TextView) view.findViewById(R.id.txt_device_ip);
number = (TextView) view.findViewById(R.id.txt_device_number);
id = (TextView) view.findViewById(R.id.txt_device_id);
imageViewContextMenu = (ImageView) view.findViewById(R.id.iv_context_menu);
linearLayoutDeviceClick = (LinearLayout) view.findViewById(R.id.linearLayoutDeviceClick);
imageViewContextMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Test", String.valueOf(getPosition())); //Test succes
}
});
linearLayoutDeviceClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("TestLayout", String.valueOf(getPosition())); //Test succes
}
});
}
檢查此:http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/ –