i have been trying to display images in my recyclerview, i had seen a lot of tutorials, but i can't.
this is my onBindViewholder in my adapter class
#Override
public void onBindViewHolder(#NonNull final cowviewHolder holder, int position) {
final Cow vacaslist = vacas.get(position);
holder.textViewinterno.setText(vacaslist.interno);
holder.textViewsiniiga.setText(vacaslist.siniiga);
Picasso.get().load(vacaslist.ulr)
.resize(80,80).centerCrop().error(R.drawable.ic_imageinf).into(holder.imageviewrec);
This is my database in firebase, im taking the images from storage
Thanks.. If need more info let me know
I think the problem is your ulr variable name because on firebase it is url so, if you are instantiating your Cow object using following syntax:
ref.child("Vacas").child("$id").getValue(Cow.class);
Then ulr will be null.
Related
I'm in need of advice on how to get data from the database, or whatever approach is best, from a RecyclerView adapter onBindViewHolder() method. Basically I have a list of Transactions that the ViewHolder cycles through, which contains an ID for a related entity called Payee, which I can obtain by accessing the Transaction's getPayeeByID method. (That method already exists to pull the info in the repository and Dao and works fine.) The problem is, how do I access that method from this screen? I need to know how get to it from here so I can create a new Payee based on the pulled PayeeId, in order to set the holder.payee.setText field with the name of the associated Payee. I have no idea how to do that from here.
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
final Transaction transaction = tTransactions.get(holder.getAdapterPosition());
holder.payee.setText( ????????? ) ;
holder.date.setText(date);
holder.transAmount.setText(amount);
I am happy to add more code if needed.
I realized the solution to this. I just created an instance of the repository and accessed the DB through that. See below:
AppRepository repository = new AppRepository(tContext);
final Payee payee = repository.getPayeeById(transaction.getPayeeId());
holder.payee.setText(payee.getName());
I'm having a little big problem on Android Studio. A have an object "Sport" that can have multiple lessons. So inside this object there is a list.
public class Sport implements Serializable {
private String cid;
private String cname;
String csportpic;
long ccreatedat;
List<Lesson> lessons;
public Sport() {
}
The object has gets and sets for each element. So the data coming from Firebase in well placed.
In a recycleview I want to display the lessons data and also some variable of the object sport(cname, cid), so I'm passing to the recycleview constructor the object Sport.
Do you have any ideia how to perform a loop through lesson List in a recyclerview? Can it be done inside onBindViewHolder?
Sorry, got it working.
For some reason the first loop was not working correctly. Perhaps the Object was not well written, or the query to the database.
public void onBindViewHolder(#NonNull final CoachVH holder, final int position)
{
for (Lesson lesson:sportlesson.get(position).getLessons())
{
holder.classid.setText(String.valueOf(new SimpleDateFormat("dd-MM-yyyy HH:mm").format(lesson.getLessonTime())));
holder.classname.setText(sportlesson.get(position).getCname());
holder.classaddress.setText(String.valueOf(lesson.getLessonAddress()));
holder.classprice.setText(String.valueOf(lesson.getLessonPrice()));
}
}
The image is not showing up, the context is passed from the activity with the recycleView on the Adapter Constructor.
The error code is :
com.bumptech.glide.Registry$NoModelLoaderAvailableException: Failed to find any ModelLoaders for model: gs://my-data-7pt42.appspot.com/CompanyImages/aMBvmcvfh6RCwGn3n0WYCYY7Nxo1/logo.jpg
What I'm trying is :
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
StorageReference reference = firebaseStorage.getReference().child("CompanyImages/"+idParser.get(position)+"/logo.jpg");
holder.companyName.setText(allCompanies.get(position));
Glide.with(context)
.load(reference)
.into(holder.imageRowCompany);
}
I also tried replacing context with holder.imageRowCompany.getContext()
Any help would be appreciated! Thanks!
When you will log the value of reference , it will not return an Image URL of logo.png,instead you will get the location of your file on google cloud.
You need to get image url of logo.png.
Here you can check how to get the download url of any file from firebase. Link
I could get it right with Realtime Database, but I went over to Cloud FireStore and now I'm running into some problems. I want to display an image that is in Firestore via a download URL from Firestore. I'm using the FirestoreRecyclerAdapter, I want to populate an imageView in a RecyclerView.
I tried to do it the same way it worked in Realtime Database, but I get an error, but this time I get an error telling me NumberFormatException: For input string:
#Override
protected void onBindViewHolder(#NonNull NoteHolder holder, int p,
#NonNull promo_one_data promo_one) {
holder.produk_product.setText(promo_one.getProduct());
holder.produk_discription.setText(promo_one.getDiscription());
holder.produk_discription_two.setText(promo_one.getDiscription_two());
holder.produk_size.setText(promo_one.getSize());
holder.produk_product_two.setText(promo_one.getProduct_two());
holder.produk_price.setText(promo_one.getPrice());
holder.produk_department.setText(promo_one.getDepartment());
if ("1".equals(holder.produk_department.getText().toString())) {
holder.itemView.setBackgroundColor(Color.parseColor("#FFCDD2"));
} else if ("2".equals(holder.produk_department.getText().toString())) {
holder.itemView.setBackgroundColor(Color.parseColor("#FFA6AF"));
} else {
holder.itemView.setBackgroundColor(Color.WHITE);
}
holder.produk_image.setImageResource(Integer.parseInt(promo_one.getImage()));
Picasso.get().load(promo_one.getImage()).into(holder.produk_image);
}
#NonNull
#Override
public NoteHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_promo, parent, false);
return new NoteHolder(v);
}
How can I display an image in a recyclerView from Cloud Firestore. It shows me "java.lang.NumberFormatException: For input string:...(the URL here), which I could gather means the string is to long to convert into a int to fill the imageView. How do I do this, or is there a way around? Or even how do I shorten the URL, or maybe is there a way to do it and not use Picasso?
Your problem is this line :
holder.produk_image.setImageResource(Integer.parseInt(promo_one.getImage()));
you should not be trying to parse the URL of the image to an integer here, the next line using Picasso:
Picasso.get().load(promo_one.getImage()).into(holder.produk_image);
should handle the image loading for you.
project tree image in this link
I am developing a social media app
In the Firebase database,
There will be Users node,posts node,likes node and request type nodes
Users nodes contains fields which represents users details and it has a uid which is like a key
Under the posts node, there will be a postskey within it there will be the details of the posts like uid,profileimage,postimage, description,date,time,fullname
The uid in the posts node is the uid in the Users node
I successfully uploaded images into the firebase storage and its url would be in the postimage field within the child node
To retrieve the particular users posts and display it in the particular users profile I tried this code which I enclosed in the images
But the posts of the user doesn't shows and white blank activity only shows up
Can u guide me to achieve my expected result
I am not good in English
Sorry,if you cannot understand my question because of my poor English
within OnCreate ,
mAuth=FirebaseAuth.getInstance();
currentUserID=mAuth.getCurrentUser().getUid();
PostsRef=FirebaseDatabase.getInstance().getReference().child("Posts");
myPostsList=(RecyclerView)findViewById(R.id.my_all_posts_list);
myPostsList.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
myPostsList.setLayoutManager(linearLayoutManager);
DisplayMyAllPosts();
within Displaymyallposts method
private void DisplayMyAllPosts() {
Query myPostsQuery=PostsRef.orderByChild("uid").startAt(currentUserID).endAt(currentUserID+"\uf8ff");
FirebaseRecyclerOptions<Posts> options=new FirebaseRecyclerOptions.Builder<Posts>().setQuery(myPostsQuery,Posts.class).build();
FirebaseRecyclerAdapter<Posts,MyPostsViewHolder> firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<Posts, MyPostsViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull MyPostsViewHolder holder, int position, #NonNull Posts model) {
holder.fullname.setText(model.getFullname());
holder.date.setText(model.getDate());
holder.time.setText(model.getTime());
holder.description.setText(model.getDescription());
Picasso.get().load(model.getProfileimage()).into(holder.profileimage);
Picasso.get().load(model.getPostimage()).into(holder.postImage);
}
#NonNull
#Override
public MyPostsViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.all_posts_layout,viewGroup,false);
MyPostsViewHolder viewHolder=new MyPostsViewHolder(view);
return viewHolder;
}
};
myPostsList.setAdapter(firebaseRecyclerAdapter);
}
public static class MyPostsViewHolder extends RecyclerView.ViewHolder{
TextView fullname,date,time,description;
CircleImageView profileimage;
ImageView postImage;
public MyPostsViewHolder(#NonNull View itemView) {
super(itemView);
fullname=itemView.findViewById(R.id.post_user_name);
date=itemView.findViewById(R.id.post_date);
time=itemView.findViewById(R.id.post_time);
description=itemView.findViewById(R.id.post_description);
profileimage=itemView.findViewById(R.id.post_profile_image);
postImage=itemView.findViewById(R.id.post_image);
}
}
The post is retrieved
it's because of my silly mistakes
I forgot to give startlistening
That's the reason for not been able to retrieve the post
But there is an another problem
Except the image all other fields are displaying
But not the image
The image is still blank