亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未連接適配器;跳過布局跳過 1 到 2 幀

未連接適配器;跳過布局跳過 1 到 2 幀

搖曳的薔薇 2024-01-28 16:45:04
我嘗試尋找答案,但沒有任何效果,但我相信這段代碼是有問題的,調試器說這是我的文件的鏈接: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();        }    });
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

在你的 onCreate 里面:


// Set up your RecyclerView with the appropriate Layout Manager

RecyclerView myRecycler = findViewById(R.id.my_recycler_id);

myRecycler.setLayoutManager(new LinearLayoutManager(this));


// Create your data set

myData = new ArrayList<MyDataType>();


// Create an instance of your adapter passing the data set into the constructor

myAdapter = new MyAdapter(this, myData);


// Set the Adapter on the RecyclerView directly within onCreate

// so that it doesn't get skipped

myRecycler.setAdapter(myAdapter);

在您的事件偵聽器回調中:


@Override

public void onDataChange(DataSnapshot snapshot){

    // Add the new data to your data set ex. myData.add(newData)

    // ...


    // After adding to the data set,

    // update the data using a custom function you define in your Adapter's class

    myAdapter.updateData(myData);

}

在 Adapter 類中,創建一個函數來更新 Adapter 的數據集:


public void updateData(ArrayList<MyDataType> newDataSet){

    myAdapterDataSet = newDataSet;


    // Let the Adapter know the data has changed and the view should be refreshed

    notifyDataSetChanged();

}


查看完整回答
反對 回復 2024-01-28
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號