Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - cannot reslove symbol 'viewHolder'

Can not resolve symbol 'viewHolder'....And when I change it to 'holder' nothing is changed ... this is part of my code (the Custom Class)

My code :

private void DisplayAllUsersPosts() {


        FirebaseRecyclerAdapter<Posts, PostsViewHolder> firebaseRecyclerAdapter =

                new FirebaseRecyclerAdapter<Posts, PostsViewHolder>(Posts.class, R.layout.all_posts_layout, PostsViewHolder.class, PostsRef) {
                    @Override
                    protected void onBindViewHolder(@NonNull PostsViewHolder holder, int position, @NonNull Posts model) {


                        viewHolder.setFullname(model.getFullname());
                        viewHolder.setTime(model.getTime());
                        viewHolder.setDate(model.getDate());
                        viewHolder.setDescription(model.getDescription());
                        viewHolder.setProfileimage(getApplicationContext(), model.getProfileimage());
                        viewHolder.setPostimage(getApplicationContext(), model.getPostimage());

                    }

                    @NonNull
                    @Override
                    public PostsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {


                        View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.all_posts_layout, parent, false);
                        PostsViewHolder viewHolder = new PostsViewHolder(view);
                        return viewHolder;


                    }
                };
        postList.setAdapter(firebaseRecyclerAdapter);



    }
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Try changing "holder" by "viewHolder" in the parameter of onBindViewHolder().

                @Override
                protected void onBindViewHolder(@NonNull PostsViewHolder viewHolder, int position, @NonNull Posts model) {


                    viewHolder.setFullname(model.getFullname());
                    viewHolder.setTime(model.getTime());
                    viewHolder.setDate(model.getDate());
                    viewHolder.setDescription(model.getDescription());
                    viewHolder.setProfileimage(getApplicationContext(), model.getProfileimage());
                    viewHolder.setPostimage(getApplicationContext(), model.getPostimage());

                }

And set values to adapter as below

    FirebaseRecyclerAdapter mAdapter = new FirebaseRecyclerAdapter(yourList);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

and make separate java file for FirebaseRecyclerAdapter. Dont write it in function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...