Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

android - E/RecyclerView﹕ No adapter attached; skipping layout

By the title of this question, its easily understandable that, the adapter of recyclerview is not set inside a UI thread. But in my case to avoid that I have tried doing it even on UI thread but still no luck.

I am using FirebaseUI for my app. Below is the code snippet:

public static void getUserFromUserId(@NonNull DatabaseReference dbRef, @NonNull String userId) {
    dbRef.child(USERS).child(userId)
            .addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    User user = dataSnapshot.getValue(User.class);
                    FriendsActivity.this.runOnUiThread(new Handler() {
                        @Override
                        public void run() {
                            loadFriends(user);
                        }
                    });

                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    FirebaseCrash.report(databaseError.toException());
                }
            });
}

private void loadFriends(User user) {
    Query friendsRef = ;  // your firebase DatabseReference path
    FirebaseRecyclerAdapter<Friend, FriendViewHolder> adapter =
            new FirebaseRecyclerAdapter<Friend, FriendViewHolder>(Friend.class,
                    R.layout.item_challenge, FriendViewHolder.class, friendsRef) {
                @Override
                protected void populateViewHolder(FriendViewHolder viewHolder, Friend model, int position) {
                    viewHolder.setFriendName(model.getName());
                    viewHolder.setFriendPic(FriendActivity.this, model.getProfilePic());
                }
            };
    mRecyclerView.setAdapter(adapter);
}

My Activity's onCreate() method has below code related to RecyclerView:

mRecyclerView = (RecyclerView) findViewById(R.id.challenge_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(layoutManager);

I dont understand why even after calling loadFriends inside runOnUiThread, why the error still persists.

Any help is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...