常见问题解决
设置 OnItemClickListener
class MyAdapter extends android.support.v7.widget.RecyclerView.Adapter<MyAdapter.ViewHolder> {
private OnItemClickListener mItemClickListener;
interface OnItemClickListener {
void onItemClick(int position);
}
MyAdapter(OnItemClickListener itemClickListener) {
mItemClickListener = itemClickListener;
}
// ...
static class ViewHolder extends RecyclerView.ViewHolder {
ViewHolder(View v, final OnItemClickListener listener) {
super(v);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onItemClick(getLayoutPosition());
}
});
}
}
}
RecyclerView.Adapter mAdapter = new MyAdapter(new MyAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
// ...
}
});
mRecyclerView.setAdapter(mAdapter);
解决 ScrollView 嵌套 RecyclerView 的显示及滑动问题
一种方法是使用 NestedScrollView,还有其它方法,
参见 https://segmentfault.com/a/1190000011553735
文档信息
- 本文作者:王玉镇wangyuzhen
- 本文链接:https://wangyuzhen666.github.io//wiki/android-view-recyclerview/
- 版权声明:Creative Commons 4.0 传播此文章时,您需要遵守知识共享协议。 署名(BY)&非商业性(NC)&相同方式共享(SA)------------------------------- When disseminating this article, you need to adhere to a Creative Commons license. Attribution (BY) & Non-Commercial (NC) & Shareby Manner (SA) .(Creative Commons 4.0)