0

I have tried looking for the answer but none works but i believe that this code is a problem,debugger says that

Here is the link to my file : TodoListApp

Skipped 1 frames! The application may be doing too much work on its main thread

// 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();
        }
    });
  • Does this answer your question? [E/RecyclerView: No adapter attached; skipping layout -- when making a todo list app](https://stackoverflow.com/questions/58034951/e-recyclerview-no-adapter-attached-skipping-layout-when-making-a-todo-list) – Sammy T Nov 02 '19 at 02:05
  • @SammyT hello could you modify my code,because i have seen your code in the link that you gave but i dont understand in what part do i need to change it.thanks – Ian Indratama Nov 02 '19 at 04:45
  • Did you read the explanation about what causes this error? What part do you need clarification on? – Sammy T Nov 02 '19 at 05:30
  • @SammyT yes i did,the code and the explanation about the error is similar and i think thats because i watched the same tutorial like him – Ian Indratama Nov 02 '19 at 05:44
  • do you mind to look and change my code ? i will give you the link – Ian Indratama Nov 02 '19 at 05:46
  • It wouldn't be beneficial for me to re-write your code for you. If you have a specific question regarding the issue or how to resolve it, I would be willing to answer or clarify that for you. – Sammy T Nov 02 '19 at 06:11
  • first of all thanks for answering my question @SammyT .the problem is ,i dont understand how to modify my code to be like yours.here is the comparison code : https://prnt.sc/prf75h – Ian Indratama Nov 02 '19 at 06:45

1 Answers1

0

Inside your 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);

Inside your Event Listener callback:

@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);
}

Inside your Adapter class, create a function to update your Adapter's data set:

public void updateData(ArrayList<MyDataType> newDataSet){
    myAdapterDataSet = newDataSet;

    // Let the Adapter know the data has changed and the view should be refreshed
    notifyDataSetChanged();
}
Sammy T
  • 1,924
  • 1
  • 13
  • 20
  • thanks a lot @SammyT its working now,but i have another problem which is the debugger says that : I/Choreographer: Skipped 8 frames! The application may be doing too much work on its main thread. I/Choreographer: Skipped 76 frames! The application may be doing too much work on its main thread. I/Choreographer: Skipped 172 frames! The application may be doing too much work on its main thread. I/Choreographer: Skipped 350 frames! The application may be doing too much work on its main thread. once it goes to skipped more than 200 frames,the app frezee – Ian Indratama Nov 02 '19 at 09:51
  • @IanIndratama You'll want to research Threads and Background Processing for Android. – Sammy T Nov 02 '19 at 21:49