常见问题解决
设置 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
文档信息
- 本文作者:Shilin Wang
- 本文链接:https://beatlesnull.github.io/wiki/android-view-recyclerview/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)