Advertisement
rachmadi

GridAdapter1 Pelancong

Feb 13th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. package mdp.ac.id.pelancong;
  2.  
  3. import android.content.Context;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.widget.BaseAdapter;
  8. import android.widget.ImageView;
  9. import android.widget.TextView;
  10.  
  11. import com.squareup.picasso.Picasso;
  12.  
  13. import java.util.ArrayList;
  14. import java.util.List;
  15.  
  16. /**
  17.  * Created by rachmadi on 2/8/17.
  18.  */
  19.  
  20. public class GridAdapter extends BaseAdapter {
  21.     private List<Location> locations = new ArrayList<>();
  22.     private final Context context;
  23.  
  24.     public GridAdapter(Context context, List<Location> locations) {
  25.         this.context = context;
  26.         this.locations = locations;
  27.     }
  28.  
  29.     @Override
  30.     public int getCount() {
  31.         return locations.size();
  32.     }
  33.  
  34.     @Override
  35.     public Location getItem(int position) {
  36.         return locations.get(position);
  37.     }
  38.  
  39.     @Override
  40.     public long getItemId(int position) {
  41.         return position;
  42.     }
  43.  
  44.     @Override
  45.     public View getView(int position, View convertView, ViewGroup parent) {
  46.  
  47.         if (convertView == null) {
  48.             convertView = LayoutInflater.from(context)
  49.                     .inflate(R.layout.grid_item, parent, false);
  50.         }
  51.  
  52.         ImageView imageView = (ImageView) convertView.findViewById(R.id.ivThumbnail);
  53.         TextView textView = (TextView) convertView.findViewById(R.id.tvLocationName);
  54.  
  55.         Location location = getItem(position);
  56.  
  57.         Picasso.with(context)
  58.                 .load(location.getLocThumbnailUrl())
  59.                 .into(imageView);
  60.  
  61.         textView.setText(location.getLocName());
  62.  
  63.         return convertView;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement