两次单击BottomNavigationBar时,RecyclerView不显示项目

时间:2020-04-18 05:37:03

标签: android android-recyclerview bottomnavigationview

我在BottonNavigationView活动的一部分内有一个回收站视图。我有三列,每列中都有一个RecyclerView。当我两次单击视图时,RecyclerView项消失了。

这是BottomNavActivity。我没有改变任何事情。这是AndroidStudio中的BottomNavActivity模板。

public class BottomActivityHome extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_home);
        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);
    }

}

这是BottonNavActivity的布局。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@drawable/bottom_nav_bar_colors"
        app:itemTextColor="@drawable/bottom_nav_bar_colors"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        android:layout_marginBottom="50dp"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

这也是片段的onViewCreated方法

super.onViewCreated(view, savesInstanceState);
        ArrayList<MetricDataModel> amdm = new ArrayList<>();
        amdm.add(new MetricDataModel("<random Id>", "100 gms"));
        amdm.add(new MetricDataModel("<random Id>", "200 gms"));
        for (int i = 0; i < 5; i++) {
            mDataset.add(new CommodityDataModel(
                    "<name>",
                    "<Link for image>",
                    amdm,
                    "gms",
                    22.4
            ));
        }

        recyclerView = view.findViewById(R.id.rcyview_commodities);

        layoutManager = new LinearLayoutManager(this.getContext());
        recyclerView.setLayoutManager(layoutManager);

        adapter = new CommoditiesAdapter(mDataset, this.getContext());
        recyclerView.setAdapter(adapter);

当我单击底部按钮两次时,“回收站”视图突然停止显示并显示黑屏。

这是我第二次点击时显示的错误。

E/RecyclerView: No adapter attached; skipping layout
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
I/art: Do partial code cache collection, code=42KB, data=62KB
I/art: After code cache collection, code=42KB, data=62KB
    Increasing code cache capacity to 256KB
I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP

当我转到其他页面并返回时,效果很好。但是当我在同一页面上单击两次时,它不起作用。

0 个答案:

没有答案