Can't find what's wrong in onBindViewHolder in FirebaseRecyclerAdapter Class - android

I'm trying to display an image and three textViews in recyclerView using Firebase but all i'm getting is a blank page. I'm thinking there's something wrong with the onBindViewHolder method, but i can't seem to find what.
onCreate
mFoodList=(RecyclerView)findViewById(R.id.foodList);
mFoodList.setHasFixedSize(true);
mFoodList.setLayoutManager(new LinearLayoutManager(this));
mDatabase= FirebaseDatabase.getInstance().getReference().child("Item");
mQuery=mDatabase.orderByKey();
mOptions=new FirebaseRecyclerOptions.Builder<Food>().setQuery(mQuery, Food.class).build();
mAuth=FirebaseAuth.getInstance();
mAuthListener=new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser()==null){
Intent loginIntent=new Intent(MenuActivity.this,MainActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(loginIntent);
}
}
};
onStart - This is where i'm having problems.
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
FBRA = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(mOptions) {
#Override
protected void onBindViewHolder(#NonNull FoodViewHolder viewHolder, int position, #NonNull Food model) {
viewHolder.setName(model.getName());
viewHolder.setPrice(model.getPrice());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getApplicationContext(),model.getImage());
}
#Override
public FoodViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.singlemenuitem, parent, false);
return new FoodViewHolder(view);
}
};
mFoodList.setAdapter(FBRA);
}
FoodViewHolder
public static class FoodViewHolder extends RecyclerView.ViewHolder{
View mView;
public FoodViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setName(String name){
TextView food_name=(TextView)mView.findViewById(R.id.foodName);
food_name.setText(name);
}
public void setPrice(String price){
TextView food_price=(TextView)mView.findViewById(R.id.foodPrice);
food_price.setText(price);
}
public void setDesc(String desc){
TextView food_desc=(TextView)mView.findViewById(R.id.foodDesc);
food_desc.setText(desc);
}
public void setImage(Context ctx, String image){
ImageView food_image=(ImageView)mView.findViewById(R.id.foodImage);
Picasso.with(ctx).load(image).into(food_image);
}
}

Unless you're using FirebaseRecyclerOptions.Builder#setLifecycleOwner(this), you'll have to manually call FirebaseRecyclerAdapter#[start/stop]Listening(). I would recommend reading the documentation.

As said by SUPERCILEX, you are using FirebaseRecyclerOption.Builder,
so you need to manually start and stop FirebaseRecyclerView listening.
So put Onstart()
mFoodList.startListening();
and OnStop()
mFoodList.stopListening();

Related

Putting data from a subcollection in a second Layout with FirebaseUI

I want to open the data of a Firebase subcollection in a new RecyclerView. The Main Activity has a RecyclerView filled with the data from the first collection and a second activity should be opened through a click on one of the items.This second activity would have the second RecyclerView. My main Activity works fine and I can see all my data. But when I click on one of the items, my app crashes.
This is my MainActivity
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference notebookRef = db.collection("Notebook");
private KisteAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton buttonAddKiste = findViewById(R.id.button_add_kiste);
buttonAddKiste.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, NewKisteActivity.class));
}
});
setUpRecyclerView();
}
private void setUpRecyclerView(){
Query query = notebookRef.orderBy("priority", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Kiste> options = new FirestoreRecyclerOptions.Builder<Kiste>()
.setQuery(query, Kiste.class)
.build();
adapter = new KisteAdapter(options);
final RecyclerView recyclerView = findViewById(R.id.recycler_view_kiste);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT |ItemTouchHelper.RIGHT) {
#Override
public boolean onMove(#NonNull RecyclerView recyclerView, #NonNull RecyclerView.ViewHolder viewHolder, #NonNull RecyclerView.ViewHolder target) {
return false;
}
#Override
public void onSwiped(#NonNull RecyclerView.ViewHolder viewHolder, int direction) {
adapter.deleteKiste(viewHolder.getAdapterPosition());
final DocumentReference docRef = adapter.getSnapshots().getSnapshot(viewHolder.getAdapterPosition()).getReference();
final Kiste kiste = adapter.getSnapshots().getSnapshot(viewHolder.getAdapterPosition()).toObject(Kiste.class);
Snackbar.make(recyclerView, "Item deleted", Snackbar.LENGTH_LONG)
.setAction("Undo", new View.OnClickListener() {
#Override
public void onClick(View v) {
docRef.set(kiste);
}
}).show();
}
#Override
public void onChildDraw(#NonNull Canvas c, #NonNull RecyclerView recyclerView, #NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
new RecyclerViewSwipeDecorator.Builder(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
.addBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorAccent))
.addActionIcon(R.drawable.ic_delete_)
.create()
.decorate();
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}).attachToRecyclerView(recyclerView);
adapter.setOnKisteClickListen(new KisteAdapter.onItemClickListener() {
#Override
public void onKisteClick(DocumentSnapshot documentSnapshot, int position) {
final DocumentReference docRef = documentSnapshot.getReference();
final CollectionReference colRef = documentSnapshot.getReference().collection("A");
final Intent intent = new Intent(MainActivity.this,SecondaryActivity.class);
colRef.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (queryDocumentSnapshots.isEmpty()){
colRef.add(new Item("DFB","SGRDG",5));
/*intent.putExtra("Document Reference",docRef.getId());
intent.putExtra("Collection Reference",colRef.getId());*/
startActivity(intent);
}
else {
startActivity(intent);
}
}
});
}
});
}
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
this is the Class Kiste, which the first RecyclerView gets
public class Kiste {
private String title;
private int priority;
public Kiste(){
}
public Kiste(String title, int priority){
this.title= title;
this.priority = priority;
}
public String getTitle() {
return title;
}
public int getPriority() {
return priority;
}
}
And this is the adapter
public class KisteAdapter extends FirestoreRecyclerAdapter<Kiste, KisteAdapter.KisteHolder> {
private onItemClickListener listener;
public KisteAdapter(#NonNull FirestoreRecyclerOptions<Kiste> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull KisteHolder holder, int position, #NonNull Kiste model) {
holder.textViewTitle.setText(model.getTitle());
holder.textViewPriority.setText(String.valueOf(model.getPriority()));
}
#NonNull
#Override
public KisteHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.kiste_item,parent,false);
return new KisteHolder(v);
}
public void deleteKiste(int position){
getSnapshots().getSnapshot(position).getReference().delete();
}
class KisteHolder extends RecyclerView.ViewHolder{
TextView textViewTitle;
TextView textViewPriority;
public KisteHolder(#NonNull View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.text_view_title);
textViewPriority = itemView.findViewById(R.id.text_view_priority);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION && listener!= null){
listener.onKisteClick(getSnapshots().getSnapshot(position),position);
}
}
});
}
}
public interface onItemClickListener {
void onKisteClick(DocumentSnapshot documentSnapshot, int position);
}
public void setOnKisteClickListen (onItemClickListener listener) {this.listener = listener;}
}
Since that worked for me, I tried doing the same with the subcollection (As I was still testing if it would work, I just used one DocumentPath that I knew existed ) but as I said above the app keeps crashing.
Here is the secondActivity
public class SecondaryActivity extends AppCompatActivity {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference colRef = db.collection("Notebook").document(
"JGBzWBwCASivfAjuF8xE").collection("A");
private ItemAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secondary);
FloatingActionButton buttonAddItem = findViewById(R.id.button_add_item);
setupRecyclerView();
}
private void setupRecyclerView(){
Query query2 = colRef.orderBy("priority", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Item> options = new FirestoreRecyclerOptions.Builder<Item>()
.setQuery(query2, Item.class)
.build();
adapter = new ItemAdapter(options);
final RecyclerView recyclerView = findViewById(R.id.recycler_view_item);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
}
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
the Class Item:
public class Item {
//private Bitmap imageItem;
private String itemName;
private String itemQuantity;
private int priority;
public Item(){
}
public Item( String itemName, String itemQuantity, int priority){
//this.imageItem = imageViewItem;
this.itemName = itemName;
this.itemQuantity = itemQuantity;
this.priority = priority;
}
/*public Bitmap getImageItem() {
return imageItem;
}*/
public String getItemName() {
return itemName;
}
public String getItemQuantity() {
return itemQuantity;
}
public int getPriority() {
return priority;
}
}
and the adapter :
public class ItemAdapter extends FirestoreRecyclerAdapter<Item, ItemAdapter.ItemHolder> {
public ItemAdapter(#NonNull FirestoreRecyclerOptions<Item> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull ItemHolder holder, int position, #NonNull Item model) {
//holder.imageViewItem.setImageBitmap(model.getImageItem());
holder.textViewTitle.setText(model.getItemName());
holder.textViewQuantity.setText(model.getItemQuantity());
holder.textViewPriority.setText(String.valueOf(model.getPriority()));
}
#NonNull
#Override
public ItemHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_item,parent,false);
return new ItemHolder(v);
}
class ItemHolder extends RecyclerView.ViewHolder{
//ImageView imageViewItem;
TextView textViewTitle;
TextView textViewQuantity;
TextView textViewPriority;
public ItemHolder(#NonNull View itemView){
super(itemView);
//imageViewItem.findViewById(R.id.image_view_item);
textViewTitle.findViewById(R.id.text_view_item_name);
textViewQuantity.findViewById(R.id.text_view_item_quantity);
textViewPriority.findViewById(R.id.text_view_priority2);
}
}
}
I would really appreciate it if someone could help me figure out what the problem is.
Thanks for pointing out the error in the console, now it's much easier for us to see where the problem is without the need of reading your whole code :D
You're getting an error in line 47 of your ItemAdapter class. I can't see exactly which line it is, but I'm certain the error is inside your ViewHolder.
class ItemHolder extends RecyclerView.ViewHolder{
//ImageView imageViewItem;
TextView textViewTitle;
TextView textViewQuantity;
TextView textViewPriority;
public ItemHolder(#NonNull View itemView){
super(itemView);
//imageViewItem.findViewById(R.id.image_view_item);
THESE LINES OF CODE -----------------------------------------------------------------
textViewTitle.findViewById(R.id.text_view_item_name);
textViewQuantity.findViewById(R.id.text_view_item_quantity);
textViewPriority.findViewById(R.id.text_view_priority2);
-------------------------------------------------------------------------------------
}
}
replace them with:
this.textViewTitle = (TextView) itemView.findViewById(R.id.text_view_item_name); // and so on...
You can check out this example:
https://www.javatpoint.com/android-recyclerview-list-example

NullPointerException at FirebaseRecyclerAdapter.startListening()

I've got a problem with my app. I am trying to show all my user's list and their details (status, phone number), but I keep on getting the null pointer exception error on the onStart method. Here is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_customer_status);
...
}
#Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
options =
new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(mUserDbase, Users.class)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {
#NonNull
#Override
public UsersViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.activity_customer_status, parent, false);
return new UsersViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull UsersViewHolder usersViewHolder, int i, #NonNull Users users) {
usersViewHolder.setName(users.getName());
usersViewHolder.setPhone(users.getPhone());
usersViewHolder.setStatus(users.getStatus());
}
};
mUserList.setAdapter(firebaseRecyclerAdapter);
}
#Override
protected void onStop() {
super.onStop();
firebaseRecyclerAdapter.stopListening();
}
// View Holder Class
public static class UsersViewHolder extends RecyclerView.ViewHolder{
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setName (String name){
TextView userNameView = (TextView) mView.findViewById(R.id.name_text);
userNameView.setText(name);
}
public void setPhone (String phone){
TextView userNameView = (TextView) mView.findViewById(R.id.phone_text);
userNameView.setText(phone);
}
public void setStatus (String status){
TextView userNameView = (TextView) mView.findViewById(R.id.status_text);
userNameView.setText(status);
}
}
}
I've followed this question: Error in FirebaseListAdapter.startListening(), which explains that the activity life cycle works as (onCreate>onStart>onResume), so assuming that (i'm a newb) I placed my on start code above my firebaseRecyclerAdapter. I've also followed this question as a guide but it didn't help me either. Please help
You are using the pointer firebaseRecyclerAdapter before initializing it.
firebaseRecyclerAdapter = new FirebaseRecyclerAdapte(){...};
firebaseRecyclerAdapter.startListening();
mUserList.setAdapter(firebaseRecyclerAdapter);

Output not showing when the firebase ui upgrade to 3.2.2

When i upgrade my firebase-ui version to 3.2.2 the firebaserecycleradapter doesn't show any output the code of mine. at first when i got multidex error then i upgrade all library version to lastest version on dependency of app lvl gradle and after upgrade the problem is found the Firebaserecycleradapter method then i search it and write after run the app the list view are not displaying plz help me.
onStart():
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions <Users> options = new FirebaseRecyclerOptions.Builder<Users>()
.setQuery(mUserDatabase,Users.class)
.build();
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {
#NonNull
#Override
public UsersViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.user_list_layout, parent, false);
return new UsersViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull UsersViewHolder holder, int position, #NonNull Users model) {
holder.setName(model.getName());
holder.setStatus(model.getStatus());
holder.setRIDNo(model.getRidno());
holder.setUserImage(model.getThumb_image(), getApplicationContext());
//to get key
final String user_id = getRef(position).getKey();
holder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent profileIntent = new Intent(UsersActivity.this, ProfileActivity.class);
profileIntent.putExtra("user_id", user_id);
startActivity(profileIntent);
}
});
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
and the viewholder is:
//User list viewholder
public static class UsersViewHolder extends RecyclerView.ViewHolder {
static View mView;
private CircleImageView mUserView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public static void setName(String name){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
public static void setStatus(String status){
TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_status);
userStatusView.setText(status);
}
public static void setRIDNo(String ridno){
TextView userRIDNoView = (TextView) mView.findViewById(R.id.user_single_ridno);
userRIDNoView.setText(ridno);
}
public static void setUserImage(String thumb_image, Context ctx){
CircleImageView userImageView = (CircleImageView) mView.findViewById(R.id.user_single_image);
Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar).into(userImageView);
}
}
In order to make your code work, please consider using the following steps.
Remove the static from the declaration of your UsersViewHolder class. Should be only:
public class UsersViewHolder extends RecyclerView.ViewHolder {/* ... */}
Remove the static keyword also from the mView field and all your methods. Your holder class should look like this:
public class UsersViewHolder extends RecyclerView.ViewHolder {
private View mView;
private CircleImageView mUserView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name){
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
public void setStatus(String status){
TextView userStatusView = (TextView) mView.findViewById(R.id.user_single_status);
userStatusView.setText(status);
}
public void setRIDNo(String ridno){
TextView userRIDNoView = (TextView) mView.findViewById(R.id.user_single_ridno);
userRIDNoView.setText(ridno);
}
public void setUserImage(String thumb_image, Context ctx){
CircleImageView userImageView = (CircleImageView) mView.findViewById(R.id.user_single_image);
Picasso.with(ctx).load(thumb_image).placeholder(R.drawable.default_avatar).into(userImageView);
}
}
Move all the code from the onStart() method inside onCreate() method except this line of code:
super.onStart();
Make your firebaseRecyclerAdapter varaible global:
private FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter;
Remove FirebaseRecyclerAdapter<Blog, BlogViewHolder> from the onCreate() method.
Add the following lines of code in the onStart() and onStop() methods.
#Override
protected void onStart() {
super.onStart();
firebaseRecyclerAdapter.startListening();
}
#Override
protected void onStop() {
super.onStop();
if(firebaseRecyclerAdapter != null) {
firebaseRecyclerAdapter.stopListening();
}
}
If you are using authentication, please also don't forget to add this line of code inside onStart() method:
firebaseAuth.addAuthStateListener(authStateListener);

How to Pass TextView text from Recyclerview to other Activity in Android

I created a simple application which contain RecyclerView TextView and Images loaded from the Firebase.
Now I want to pass the text from TextView to other activity.
The TextView is in RecyclerView:
The code:
FirebaseRecyclerAdapter<Blog,BlogViewHolder> firebaseRecyclerAdapter=new
FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.blog_row,
BlogViewHolder.class,
mDatabase
) {
#Override
protected void populateViewHolder(final BlogViewHolder viewHolder,
Blog model, final int position) {
final String post_keyy=getRef(position).getKey();
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImag(getApplicationContext(),model.getImage());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
public static class BlogViewHolder extends RecyclerView.ViewHolder
{
View mView;
TextView post_title,post_desc;
ImageView post_imge;
public BlogViewHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setTitle(String title)
{
post_title=(TextView)mView.findViewById(R.id.posttitle);
post_title.setText(title);
}
public void setDesc(String desc)
{
post_desc=(TextView)mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
public void setImag(Context ctx,String image)
{
post_imge=(ImageView) mView.findViewById(R.id.postimg);
Picasso.with(ctx).load(image).into(post_imge);
}
}
Now I want to pass post_title textview text to other activity.
You should try to add the onClickListener in the onBindViewHolder method of your RecyclerAdapter class:
#Override
public void onBindViewHolder(BlogViewHolder holder, int position) {
//Set the OnClickListener on whatever view you want to trigger when clicked.
holder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//You can get the context from the view itself.
Intent intent = new Intent(view.getContext(), theOtherActivityName.class);
//Put your intent extras.
intent.putExtra("blog_id",post_title.getText().toString());
view.getContext().startActivity(intent);
}
});
}

Android Using View Holder

I try to show in my app using firebase but not return image or the other data
please help me I use it after no any error but now I do not use this method
public class PaylasAnaSayfa extends AppCompatActivity {
private RecyclerView mBlogList;
public DatabaseReference mDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paylas_ana_sayfa);
mDatabase= FirebaseDatabase.getInstance().getReference().child("Resimler");
mBlogList= (RecyclerView) findViewById(R.id.resim_list);
mBlogList.setHasFixedSize(true);
mBlogList.setLayoutManager(new LinearLayoutManager(this));
if (mDatabase==null){
Toast.makeText(this, "veri tabanı hatası", Toast.LENGTH_SHORT).show();
}else {
FirebaseRecyclerAdapter<PaylasModel, PaylasHolder> adapter = new FirebaseRecyclerAdapter<PaylasModel, PaylasHolder>(
PaylasModel.class,
R.layout.resim_row,
PaylasHolder.class,
mDatabase
) {
#Override
protected void populateViewHolder(PaylasHolder viewHolder, PaylasModel model, int position) {
viewHolder.setImage(getApplicationContext(), model.getImgImage());
viewHolder.setBaslik(model.getImgBaslik());
viewHolder.setAciklama(model.getImgAciklama());
viewHolder.setKullanici(model.getImgKullaniciAdi());
viewHolder.setDers(model.getImgDers());
}
};
mBlogList.setAdapter(adapter);
}
}
private static class PaylasHolder extends RecyclerView.ViewHolder {
View mView;
public PaylasHolder(View itemView) {
super(itemView);
mView=itemView;
}
public void setBaslik(String baslik){
TextView tBaslik= (TextView) mView.findViewById(R.id.row_img_baslik);
tBaslik.setText(baslik);
}
public void setAciklama(String aciklama){
TextView tAciklama= (TextView) mView.findViewById(R.id.row_img_aciklama);
tAciklama.setText(aciklama);
}
public void setKullanici(String kullanici){
TextView tKullanici= (TextView) mView.findViewById(R.id.row_img_kullanici);
tKullanici.setText(kullanici);
}
public void setDers(String ders){
TextView tDers= (TextView) mView.findViewById(R.id.row_img_ders);
tDers.setText(ders);
}
public void setImage(final Context context, final String image){
final ImageView tImage= (ImageView) mView.findViewById(R.id.row_img_image);
Picasso.with(context).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(tImage, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Picasso.with(context).load(image).into(tImage);
}
});
}
}
}
using view holder do not return data
The word in square brackets is the alt text, which gets displayed if the browser can't show the image. Be sure to include meaningful alt text for screen-reading software.
First you don't need to initialize views everytime in the methods of your ViewHolder.RecyclerView reuses the view from the view pool.
private static class PaylasHolder extends RecyclerView.ViewHolder {
View mView;
TextView tBaslik;
public PaylasHolder(View itemView) {
super(itemView);
mView=itemView;
tBaslik = mView.findViewById(R.id.row_img_baslik);
//intialize all you view here once and for all.
}
public void setBaslik(String baslik){
tBaslik.setText(baslik);
}
public void setAciklama(String aciklama){
tAciklama.setText(aciklama);
}
public void setKullanici(String kullanici){
tKullanici.setText(kullanici);
}
public void setDers(String ders){
tDers.setText(ders);
}
public void setImage(final Context context, final String image){
Picasso.with(context).load(image).networkPolicy(NetworkPolicy.OFFLINE).into(tImage, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Picasso.with(context).load(image).into(tImage);
}
});
}
}
If you are very much sure about the size of the recyclerview then only use setHasFixedSize(true) otherwise it will not request layout upon the addition of data to the adapter.

Categories

Resources