Created
December 24, 2017 12:59
-
-
Save hkakutalua/fe8b64c1402d3f8bcf3a1238d161f34b to your computer and use it in GitHub Desktop.
Initial version of our PopularMoviesAdapter
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
public class PopularMoviesAdapter extends RecyclerView.Adapter<PopularMoviesAdapter.PopularMovieViewHolder> { | |
Context mContext; | |
ArrayList<String> mMoviesList; | |
public PopularMoviesAdapter(Context context) { | |
mContext = context; | |
mMoviesList = new ArrayList<>(); | |
} | |
@Override | |
public PopularMovieViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
LayoutInflater inflater = LayoutInflater.from(parent.getContext()); | |
View inflatedView = inflater.inflate(R.layout.popular_movie_list_item, parent, false); | |
return new PopularMovieViewHolder(inflatedView); | |
} | |
@Override | |
public void onBindViewHolder(PopularMovieViewHolder holder, int position) { | |
holder.mMovieInfoTextView.setText(mMoviesList.get(position)); | |
} | |
@Override | |
public int getItemCount() { | |
return (mMoviesList != null) ? mMoviesList.size() : 0; | |
} | |
public void swapMoviesList(ArrayList<String> moviesList) { | |
if (mMoviesList != null) { | |
mMoviesList = moviesList; | |
notifyDataSetChanged(); | |
} | |
} | |
class PopularMovieViewHolder extends RecyclerView.ViewHolder { | |
TextView mMovieInfoTextView; | |
public PopularMovieViewHolder(View itemView) { | |
super(itemView); | |
mMovieInfoTextView = itemView.findViewById(R.id.text_movie_info); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment