Closed JavaBoyHW closed 6 years ago
先调用
/**
* same as recyclerView.setAdapter(), and save the instance of recyclerView
*/
public void bindToRecyclerView(RecyclerView recyclerView) {
if (getRecyclerView() != null) {
throw new RuntimeException("Don't bind twice");
}
setRecyclerView(recyclerView);
getRecyclerView().setAdapter(this);
}
再调用这个
/**
* get the specific view by position,e.g. getViewByPosition(2, R.id.textView)
* <p>
* bind recyclerView {@link #bindToRecyclerView(RecyclerView)} before use!
*
* @see #bindToRecyclerView(RecyclerView)
*/
@Nullable
public View getViewByPosition(int position, @IdRes int viewId) {
checkNotNull();
return getViewByPosition(getRecyclerView(), position, viewId);
}
抛错代码
private void checkNotNull() {
if (getRecyclerView() == null) {
throw new RuntimeException("please bind recyclerView first!");
}
}
建议 通过 LinearLayoutManager.findViewByPosition(position )获取位置的view
@AllenCoder
setRecyclerView(android.support.v7.widget.RecyclerView)' has private access in 'com.chad.library.adapter.base.BaseQuickAdapter
How to solve this?
You can try :,
bindToRecyclerView(RecyclerView); mQuickAdapter.setEmptyView(layoutResId);
Hope it can help U ...
我在BaseQuickAdapter.OnItemClickListener()的点击事件中想通过adapter.getViewByPosition(position, R.id.isselected);拿到一个ImageView。但这行报错。代码如下: