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 DisplayAllUsersPo
Solution 1:
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
FirebaseRecyclerAdaptermAdapter=newFirebaseRecyclerAdapter(yourList);
RecyclerView.LayoutManagermLayoutManager=newLinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(newDefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
and make separate java file for FirebaseRecyclerAdapter. Dont write it in function.
Solution 2:
privatevoidDisplayAllUsersPosts() {
FirebaseRecyclerAdapter<Posts, PostsViewHolder> firebaseRecyclerAdapter =
newFirebaseRecyclerAdapter<Posts, PostsViewHolder>(Posts.class, R.layout.all_posts_layout, PostsViewHolder.class, PostsRef) {
@OverrideprotectedvoidonBindViewHolder(@NonNull PostsViewHolder holder, int position, @NonNull Posts model) {
holder.setFullname(model.getFullname());
holder.setTime(model.getTime());
holder.setDate(model.getDate());
holder.setDescription(model.getDescription());
holder.setProfileimage(getApplicationContext(), model.getProfileimage());
holder.setPostimage(getApplicationContext(), model.getPostimage());
}
@NonNull@Overridepublic PostsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Viewview= LayoutInflater.from(parent.getContext()) .inflate(R.layout.all_posts_layout, parent, false);
PostsViewHolderviewHolder=newPostsViewHolder(view);
return viewHolder;
}
};
postList.setAdapter(firebaseRecyclerAdapter);
}
Post a Comment for "Cannot Reslove Symbol 'viewholder'"