Open NatalieZhang opened 8 years ago
Great work finishing the stories. Here is some feedback after reviewing your code --
OnClickListener
instances in RecyclerView.Adapter.onBindViewHolder()
, which causes more objects to be created and possibly causing the garbage collector to run with higher frequncy, do the following:public class InstagramPostsAdapter extends RecyclerView.Adapter<InstagramPostsAdapter.ViewHolder> {
@Override
public void onBindViewHolder(ViewHolder holder, int i) {
InstagramPost post = posts.get(i);
holder.post = post;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
private InstagramPost post;
private Button btnDoSomethingWithPost;
public ViewHolder(View itemView) {
super(itemView);
btnDoSomethingWithPost = (Button) itemView.findViewById(R.id.btnDoSomethingWithPost);
setupListeners();
}
void setupListeners() {
btnDoSomethingWithPost.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// context can be referenced via v.getContext()
doSomethingWithPost(post);
}
});
}
}
}
Toast
that the network request failed.
Please review. @codepathreview @codepath