为什么回收视图没有一个ItemClickListener()?我在探索RecyclerView我很惊讶地看到RecyclerView没有onItemClickListener()..因为RecyclerView延展android.view.ViewGroup和ListView延展android.widget.AbsListView..然而,我通过写作解决了我的问题。onClick在我的RecyclerView.Adapter:public static class ViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
public TextView txtViewTitle;
public ImageView imgViewIcon;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
txtViewTitle = (TextView) itemLayoutView.findViewById(R.id.item_title);
imgViewIcon = (ImageView) itemLayoutView.findViewById(R.id.item_icon);
}
@Override
public void onClick(View v) {
}}但我还是想知道为什么谷歌删除了onItemClickListener()?是性能问题还是其他原因?
3 回答
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
public Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_image_and_text, parent, false);v.setOnClickListener( new MyOnClickListener());
class MyOnClickListener implements View.OnClickListener { @Override public void onClick(View v) { int itemPosition = recyclerView.indexOfChild(v); Log.e("Clicked and Position is ",String.valueOf(itemPosition)); }}
添加回答
举报
0/150
提交
取消