Created
December 29, 2017 04:37
-
-
Save nikhilbansal97/f11551b4f6c28c377a363d2cd252b844 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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