片段中带有卡片的 Recyclerview 不显示任何内容

我正在尝试制作一个里面有一个片段的活动,上面有一个recyclerView和cards。现在,它只显示活动,片段是空的,我不知道这里发生了什么。


这是的代码activity中,fragment和adapter


活动:


package com.laorden.goodreasons.habits;


import android.content.Intent;

import android.os.Bundle;

import android.support.annotation.VisibleForTesting;

import android.support.design.widget.NavigationView;

import android.support.test.espresso.IdlingResource;

import android.support.v4.view.GravityCompat;

import android.support.v4.widget.DrawerLayout;

import android.support.v7.app.ActionBar;

import android.support.v7.app.AppCompatActivity;

import android.support.v7.widget.Toolbar;

import android.view.MenuItem;

import android.view.Window;

import android.view.WindowManager;


import com.laorden.goodreasons.Injection;

import com.laorden.goodreasons.R;

import com.laorden.goodreasons.statistics.StatisticsActivity;

import com.laorden.goodreasons.util.ActivityUtils;

import com.laorden.goodreasons.util.EspressoIdlingResource;


public class HabitsActivity extends AppCompatActivity {


    private DrawerLayout mDrawerLayout;

    private HabitsPresenter mHabitsPresenter;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.habits_act);

        Window w = getWindow();

        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);



        // Set up the toolbar.

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);

        ActionBar ab = getSupportActionBar();

        ab.setHomeAsUpIndicator(R.drawable.ic_menu);

        ab.setDisplayHomeAsUpEnabled(true);


        // Set up the navigation drawer.

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

        if (navigationView != null) {

            setupDrawerContent(navigationView);

        }


DIEA
浏览 146回答 3
3回答

紫衣仙女

那是因为您在getItemCount方法中返回 0改变这一点:@Override public int getItemCount() {    return 0; }对此:@Override public int getItemCount() {    return (mData != null ?  mData.size():0);}

浮云间

你应该先设置布局管理器@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,                         Bundle savedInstanceState) {    View root = inflater.inflate(R.layout.habits_frag, container, false);    recyclerView = root.findViewById(R.id.rv_list);    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));    recyclerView.setAdapter(mListAdapter);    return root;}您还需要将 getItemCount 更改为@Override    public int getItemCount() {         if(mData!=null){return mData.size();}else return 0;    }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java