未连接适配器;从数据库获取数据并在回收器视图中显示数据时跳过布局



收到此错误,未连接适配器;跳过布局,我从数据库获取数据并将其显示在回收器视图中,在此处附加我正在设置适配器和空视图的代码,我认为此问题可能会导致,因为 recycleview 的可见性我不确定请建议,这是我设置适配器和加载器的代码

适配器

 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);
        }

    }
}

这里要记住两件事:

  1. 当您将适配器设置为没有任何数据的情况下的回收器视图时,您会发现此问题。(在您的情况下,在将适配器与回收器视图绑定之前,将 null 作为数据传递给适配器。
  2. 这只是一个警告,所以你可以忽略这一点。

发生这种情况是因为您没有在"else"中设置和适配器。通常,您会看到此错误,因为适配器为空:

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 {

还要检查是否在创建期间设置了适配器。以下是一些类似的问题:链接 1、链接 2

最新更新