Ronel101

new FoodListAdapter

Apr 19th, 2021
662
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.finalapp;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.graphics.Bitmap;
  7. import android.graphics.BitmapFactory;
  8. import android.net.Uri;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.AdapterView;
  13. import android.widget.BaseAdapter;
  14. import android.widget.Button;
  15. import android.widget.TextView;
  16.  
  17. import com.bumptech.glide.Glide;
  18. import com.google.android.gms.tasks.OnSuccessListener;
  19. import com.google.firebase.database.DatabaseReference;
  20. import com.google.firebase.database.FirebaseDatabase;
  21. import com.google.firebase.storage.FileDownloadTask;
  22. import com.google.firebase.storage.FirebaseStorage;
  23. import com.google.firebase.storage.StorageReference;
  24.  
  25. import java.io.File;
  26. import java.io.IOException;
  27. import java.util.ArrayList;
  28.  
  29. import de.hdodenhof.circleimageview.CircleImageView;
  30.  
  31. public class FoodListAdapter extends BaseAdapter {
  32.  
  33.     private ArrayList<Food> foodArrayList;
  34.     private String pic_path;
  35.     private Context context;
  36.  
  37.     private DatabaseReference ref=null;
  38.  
  39.     public FoodListAdapter(ArrayList<Food> foodArrayList, Context context, String pic_path)
  40.     {
  41.         this.foodArrayList = foodArrayList;
  42.         this.context = context;
  43.         this.pic_path=pic_path;
  44.     }
  45.  
  46.     @Override
  47.     public int getCount()
  48.     {
  49.         return this.foodArrayList.size();
  50.     }
  51.  
  52.     @Override
  53.     public Object getItem(int position)
  54.     {
  55.         return null;
  56.     }
  57.  
  58.     @Override
  59.     public long getItemId(int position)
  60.     {
  61.         return 0;
  62.     }
  63.  
  64.     @Override
  65.     public View getView(final int position, final View convertView, ViewGroup parent)
  66.     {
  67.         ref= FirebaseDatabase.getInstance().getReference("Food");
  68.  
  69.         LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  70.  
  71.         View show_food_search = layoutInflater.inflate(R.layout.foodrow, parent, false);
  72.         TextView name= (TextView)show_food_search.findViewById(R.id.foodlist_name);
  73.         TextView username= (TextView)show_food_search.findViewById(R.id.foodlist_des);
  74.  
  75.         name.setText(foodArrayList.get(position).getFoodName());
  76.         username.setText(foodArrayList.get(position).getDescription());
  77.  
  78.         final CircleImageView imageView =show_food_search.findViewById(R.id.img_FoodList);
  79.  
  80.         String picname=this.foodArrayList.get(position).getFoodpic();
  81.  
  82.         String suffix=picname.substring(picname.lastIndexOf(".")+1);
  83.  
  84.         FirebaseStorage storage = FirebaseStorage.getInstance();
  85.  
  86.         StorageReference storageRef = storage.getReference().child("Food").child(picname);
  87.  
  88.         storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
  89.             @Override
  90.             public void onSuccess(Uri uri) {
  91.                 Glide
  92.                         .with(context)
  93.                         .load(uri)
  94.                         .into(imageView);
  95.             }
  96.         });
  97.  
  98.         // final String id=this.foodArrayList.get(position);
  99.  
  100.  
  101.         return show_food_search;
  102.     }
  103. }
  104.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×