Created
June 12, 2016 19:11
-
-
Save frogermcs/13e713582fefcd87a9a90a055b2a9768 to your computer and use it in GitHub Desktop.
ViewHolder and Dagger 2 example
This file contains 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 RepositoriesListAdapter extends RecyclerView.Adapter { | |
//... | |
public static class RepositoryViewHolderNormal extends RepositoryViewHolder { | |
@Bind(R.id.tvName) | |
TextView tvName; | |
public RepositoryViewHolderNormal(View view) { | |
super(view); | |
ButterKnife.bind(this, itemView); | |
} | |
@Override | |
public void bind(Repository repository) { | |
tvName.setText(repository.name); | |
} | |
} | |
public static class RepositoryViewHolderBig extends RepositoryViewHolder { | |
@Bind(R.id.tvName) | |
TextView tvName; | |
@Bind(R.id.tvStars) | |
TextView tvStars; | |
@Bind(R.id.tvForks) | |
TextView tvForks; | |
public RepositoryViewHolderBig(View view) { | |
super(view); | |
ButterKnife.bind(this, itemView); | |
} | |
@Override | |
public void bind(Repository repository) { | |
tvName.setText(repository.name); | |
tvStars.setText("Stars: " + repository.stargazers_count); | |
tvForks.setText("Forks: " + repository.forks_count); | |
} | |
} | |
public static class RepositoryViewHolderFeatured extends RepositoryViewHolder { | |
@Bind(R.id.tvName) | |
TextView tvName; | |
@Bind(R.id.tvStars) | |
TextView tvStars; | |
@Bind(R.id.tvForks) | |
TextView tvForks; | |
public RepositoryViewHolderFeatured(View view) { | |
super(view); | |
ButterKnife.bind(this, itemView); | |
} | |
@Override | |
public void bind(Repository repository) { | |
tvName.setText(repository.name); | |
tvStars.setText("Stars: " + repository.stargazers_count); | |
tvForks.setText("Forks: " + repository.forks_count); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment