我有一个 recyclerView,它的项目包含一个按钮。当我点击按钮时,我想获得 recyclerview 项目的位置。这里的问题是,当按钮点击按钮点击事件被触发但neath下的recyclerview项目没有,点击事件不能通过顶部的按钮到recyclerview项目。如何获得此点击事件或如何将它们绑定在一起?请有人告诉我是否知道答案。
更新:我在网上找不到任何类似的帖子。通常recyclerview 包含的按钮被注册到不同的OnclickedListener。就我而言,他们需要处理相同的侦听器,尤其是 recyclerview 处理它。但是按钮只是阻止了recyclerview的点击事件。这是viewholder的代码:`public class GridViewAdapter extends RecyclerView.Adapter {
private final LinkedList<Device> mValues;
private final OnListFragmentInteractionListener mListener;
private OnLongClickListener mOnLongClickListener = null;
public GridViewAdapter(LinkedList<Device> items, OnListFragmentInteractionListener listener) {
mValues = items;
mListener = listener;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.device, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mItem = mValues.get(position);
// holder.mIconView.setImageResource(R.drawable.ic_switch);
holder.mNameView.setText(holder.mItem.device_name());
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != mListener) {
mListener.onDeviceClicked(holder.mItem);
}
}
});
}
public void deleteByDeviceCode(int deviceCode) {
for(int i=0;i<mValues.size();i++) {
if (mValues.get(i).device_code() == deviceCode) {
mValues.remove(i);
}
}
}
public void deleteByPosition(int pos) {
mValues.remove(pos);
}
public int getDeviceCodeByPosition(int pos) {
return mValues.get(pos).device_code();
}
@Override
public int getItemCount() {
return mValues.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final Button mButton;
public final TextView mNameView;
public Device mItem;
public ViewHolder(View view) {
super(view);
mView = view;
mButton = (Button) view.findViewById(R.id.dev_button);
mNameView = (TextView) view.findViewById(R.id.dev_lable);
}
@Override
public String toString() {
return super.toString() + " '" + mNameView.getText() + "'";
}
}
}`