没有适配器;从db获取数据并在recyclerview中显示时跳过布局

时间:2016-01-17 12:19:46

标签: android android-adapter android-recyclerview

获取此错误未附加适配器;跳过布局,我从数据库中获取数据并在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);

        }


    }
}

2 个答案:

答案 0 :(得分:0)

这里要记住两件事:

  1. 当您将适配器设置为您的recyclerview而没有任何数据时,您会发现此问题。 (在您使用recyclerview绑定适配器之前,您将null作为数据传递到适配器。)
  2. 这只是一个警告,所以你可以忽略它。

答案 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 {

同时检查您是否在onCreate期间设置了适配器。 以下是一些类似的问题:link1link2