Advertisement
euis_kusesa

AdapterListView

Dec 24th, 2018
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package com.example.asusx441n.examplelistviewdinamis;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.BaseAdapter;
  9. import android.widget.ImageView;
  10. import android.widget.TextView;
  11.  
  12. import com.bumptech.glide.Glide;
  13. import com.bumptech.glide.load.engine.DiskCacheStrategy;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17.  
  18. public class AdapterListView  extends BaseAdapter {
  19.     Global global = new Global();
  20.  
  21.     private Activity activity;
  22.     private ArrayList<HashMap<String, String>> data, insertData;
  23.     HashMap<String, String> order;
  24.     private static LayoutInflater inflater = null;
  25.     ImageView img;
  26.     View vi;
  27.  
  28.     public AdapterListView(Activity a, ArrayList<HashMap<String, String>> d) {
  29.         activity = a;
  30.         data = d;
  31.         inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  32.     }
  33.  
  34.     public int getCount() {
  35.         return data.size();
  36.     }
  37.  
  38.     public Object getItem(int position) {
  39.         return position;
  40.     }
  41.  
  42.     public long getItemId(int position) {
  43.         return position;
  44.     }
  45.  
  46.     @Override
  47.     public View getView(int i, View view, ViewGroup viewGroup) {
  48.         vi = view;
  49.         if (view == null)
  50.             vi = inflater.inflate(R.layout.activity_main_row, null);
  51.         HashMap<String, String> order = data.get(i);
  52.         TextView judul = (TextView) vi.findViewById(R.id.tv_tittle);
  53.         TextView tv_provinsi = (TextView) vi.findViewById(R.id.tv_provinsi);
  54.         ImageView iv_gambar = (ImageView) vi.findViewById(R.id.iv_gambar);
  55.  
  56.         judul.setText(order.get(global.DATA_TITLE));
  57.         tv_provinsi.setText(order.get(global.DATA_PROVINSI));
  58.         Glide.with(activity).load(order.get(global.DATA_IMAGE1)).thumbnail(0.5f).crossFade().diskCacheStrategy(DiskCacheStrategy.ALL)
  59.                 .into(iv_gambar);
  60.  
  61.         return vi;
  62.     }
  63.     public HashMap<String, String> getItemDisvisitoril(int position) {
  64.         return data.get(position);
  65.     }
  66.  
  67.     public void setData(ArrayList<HashMap<String, String>> data) {
  68.         this.data = data;
  69.     }
  70.  
  71.     public HashMap<String, String> getItemDetail(int position) {
  72.  
  73.         return data.get(position);
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement