1 Replies - 229 Views - Last Post: 27 May 2019 - 04:39 PM

#1 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

Firebase to Recyclerview

Posted 27 May 2019 - 03:09 PM

Am I doing something wrong? because I cant load the database on the recyclerview,

No errors found however everytime I run it, it always give me the Toast output.



This is onCreate method
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Firebase.setAndroidContext(this);


        databaseReference = FirebaseDatabase.getInstance().getReference().child("depedapp-b10c2").child("Student");
        recyclerView = findViewById(R.id.studentListRecyclerView);
        searchView = findViewById(R.id.studentListSearchView);
    }




this is the code onstart method
protected void onstart() {
        super.onstart();
        if(databaseReference != null)
        {
            databaseReference.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    if (dataSnapshot.exists())
                    {
                        list = new ArrayList<>();
                        for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren())
                        {
                            list.add(dataSnapshot1.getValue(StudentPojo.class));
                        }
                        StudentAdapter studentAdapter = new StudentAdapter(list);
                        recyclerView.setAdapter(studentAdapter);
                    }
                    else
                    {
                        Toast.makeText(MainActivity.this, "On data change", Toast.LENGTH_LONG).show();
                    }

                }


and this is my database on firebase
root is
**depedapp-b10c2.
---Student
-------stud1
-----------Age: "21"
-----------DOB: "12-12-1991"
-----------Fname: Dex
-----------Lname: Bal
-----------Sex: Male
-------stud2
-----------Age: "21"
-----------DOB: "12-12-1991"
-----------Fname: Anne
-----------Lname: Curtis
-----------Sex: Female



And there is one red line on the LogCat

 2019-05-28 09:56:06.645 5985-5985/com.example.assignment2 E/RecyclerView: No adapter attached; skipping layout 



Thanks for the help guys!

This post has been edited by awthz: 27 May 2019 - 03:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Firebase to Recyclerview

#2 ben255   User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 528
  • Joined: 09-September 13

Re: Firebase to Recyclerview

Posted 27 May 2019 - 04:39 PM

dont think you can add the adapter onstart not 100% sure tho.
also try using unique keys instead of stud1,stud2 in database then you dont have to check where youre at in the position when adding new students.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1