Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mdp.ac.id.pelancong;
- import android.content.Context;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.squareup.picasso.Picasso;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by rachmadi on 2/8/17.
- */
- public class GridAdapter extends BaseAdapter {
- private List<Location> locations = new ArrayList<>();
- private final Context context;
- public GridAdapter(Context context, List<Location> locations) {
- this.context = context;
- this.locations = locations;
- }
- @Override
- public int getCount() {
- return locations.size();
- }
- @Override
- public Location getItem(int position) {
- return locations.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = LayoutInflater.from(context)
- .inflate(R.layout.grid_item, parent, false);
- }
- ImageView imageView = (ImageView) convertView.findViewById(R.id.ivThumbnail);
- TextView textView = (TextView) convertView.findViewById(R.id.tvLocationName);
- Location location = getItem(position);
- Picasso.with(context)
- .load(location.getLocThumbnailUrl())
- .into(imageView);
- textView.setText(location.getLocName());
- return convertView;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement