Skip to content

Instantly share code, notes, and snippets.

@nikhilbansal97
Created December 29, 2017 04:37
Show Gist options
  • Save nikhilbansal97/f11551b4f6c28c377a363d2cd252b844 to your computer and use it in GitHub Desktop.
Save nikhilbansal97/f11551b4f6c28c377a363d2cd252b844 to your computer and use it in GitHub Desktop.
package com.example.nikhil.popularmovies;
import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MovieAdapter extends ArrayAdapter<Movie> {
private Context mContext;
private List<Movie> moviesList = new ArrayList<>();
public MovieAdapter(@NonNull Context context, @LayoutRes ArrayList<Movie> list) {
super(context, 0 , list);
mContext = context;
moviesList = list;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItem = convertView;
if(listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.list_item,parent,false);
Movie currentMovie = moviesList.get(position);
ImageView image = (ImageView)listItem.findViewById(R.id.imageView_poster);
image.setImageResource(currentMovie.getmImageDrawable());
TextView name = (TextView) listItem.findViewById(R.id.textView_name);
name.setText(currentMovie.getmName());
TextView release = (TextView) listItem.findViewById(R.id.textView_release);
release.setText(currentMovie.getmRelease());
return listItem;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment