获取此错误未附加适配器;跳过布局,我从数据库中获取数据并在recyclelerview中显示附加代码,其中我设置适配器,在空视图中,我认为这个问题可能因为recycleview i&#的可见性而导致39;我不确定请建议,这是我设置适配器和加载器的代码
适配器
mRecyclerView = (RecyclerView) findViewById(R.id.inboxChatList);
emptyData = (LinearLayout)findViewById(R.id.emptyData);
dataEmptyText = (TextView)findViewById(R.id.dataEmptyText);
mRecyclerView.setItemAnimator(new FadeInAnimator());
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
mShop=HomeActivity.getClaimedShop(mContext);
if (mShop.mVerifiedId != null) {
L.e("mShop.mVerifiedId",mShop.mVerifiedId);
emptyData.setVisibility(View.GONE);
if (mAdapter.getItemCount() == 0) {
emptyData.setVisibility(View.VISIBLE);
dataEmptyText.setText(R.string.text_empty_inbox);
}
// use a linear layout manager
mRecyclerView.setLayoutManager(new org.solovyev.android.views.llm.LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
getSupportLoaderManager().initLoader(mRecentChatsCallback.hashCode(), null, mRecentChatsCallback);
mAdapter = new InboxChatAdapter(mContext, null);
mRecyclerView.setAdapter(mAdapter);
}else{
emptyData.setVisibility(View.VISIBLE);
dataEmptyText.setText(R.string.not_verified);
}
加载程序详细信息
private class RecentChatCallback implements LoaderManager.LoaderCallbacks<RecentChatLoader.Result> {
boolean otpFlag = true;
@Override
public Loader<RecentChatLoader.Result> onCreateLoader(int id, Bundle args) {
return new RecentChatLoader(mContext);
}
@Override
public void onLoadFinished(Loader<RecentChatLoader.Result> loader, RecentChatLoader.Result data) {
mAdapter.changeCursor(data.cursor);
if(data.cursor.getCount()== 0){
emptyData.setVisibility(View.VISIBLE);
dataEmptyText.setText(R.string.text_empty_inbox);
mRecyclerView.setVisibility(View.INVISIBLE);
}else{
mRecyclerView.setVisibility(View.VISIBLE);
emptyData.setVisibility(View.GONE);
}
}
@Override
public void onLoaderReset(Loader<RecentChatLoader.Result> loader) {
mAdapter.changeCursor(null);
}
}
}
答案 0 :(得分:0)
这里要记住两件事:
答案 1 :(得分:0)
这是因为你没有在'else'中设置和适配。 通常,您会看到此错误,因为适配器为null:
void dispatchLayout() {
if(this.mAdapter == null) {
Log.e("RecyclerView", "No adapter attached; skipping layout");
} else if(this.mLayout == null) {
Log.e("RecyclerView", "No layout manager attached; skipping layout");
} else {