未连接适配器;跳过布局跳过 1 到 2 帧

我尝试寻找答案,但没有任何效果,但我相信这段代码是有问题的,调试器说

这是我的文件的链接:TodoListApp

跳过 1 帧!应用程序可能在其主线程上做了太多工作

// working with data

    ourdoes = findViewById(R.id.ourdoes);

    ourdoes.setLayoutManager(new LinearLayoutManager(this));

    list = new ArrayList<MyDoes>();


    // get data from firebase

    reference = FirebaseDatabase.getInstance().getReference().child("SeaLab13");

    reference.addValueEventListener(new ValueEventListener() {

        @Override

        public void onDataChange(DataSnapshot dataSnapshot) {

            // set code to retrive data and replace layout

            for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())

            {

                MyDoes p = dataSnapshot1.getValue(MyDoes.class);

                list.add(p);

            }

            doesAdapter = new DoesAdapter(MainActivity.this, list);

            ourdoes.setAdapter(doesAdapter);

            doesAdapter.notifyDataSetChanged();

        }


        @Override

        public void onCancelled(DatabaseError databaseError) {

            // set code to show an error

            Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();

        }

    });


摇曳的蔷薇
浏览 91回答 1
1回答

猛跑小猪

在你的 onCreate 里面:// Set up your RecyclerView with the appropriate Layout ManagerRecyclerView myRecycler = findViewById(R.id.my_recycler_id);myRecycler.setLayoutManager(new LinearLayoutManager(this));// Create your data setmyData = new ArrayList<MyDataType>();// Create an instance of your adapter passing the data set into the constructormyAdapter = new MyAdapter(this, myData);// Set the Adapter on the RecyclerView directly within onCreate// so that it doesn't get skippedmyRecycler.setAdapter(myAdapter);在您的事件侦听器回调中:@Overridepublic void onDataChange(DataSnapshot snapshot){&nbsp; &nbsp; // Add the new data to your data set ex. myData.add(newData)&nbsp; &nbsp; // ...&nbsp; &nbsp; // After adding to the data set,&nbsp; &nbsp; // update the data using a custom function you define in your Adapter's class&nbsp; &nbsp; myAdapter.updateData(myData);}在 Adapter 类中,创建一个函数来更新 Adapter 的数据集:public void updateData(ArrayList<MyDataType> newDataSet){&nbsp; &nbsp; myAdapterDataSet = newDataSet;&nbsp; &nbsp; // Let the Adapter know the data has changed and the view should be refreshed&nbsp; &nbsp; notifyDataSetChanged();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java