Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SteveKamau72/bdca9be0605096b21fc1828a64838146 to your computer and use it in GitHub Desktop.
Save SteveKamau72/bdca9be0605096b21fc1828a64838146 to your computer and use it in GitHub Desktop.
Simple RecyclerView Adapter
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.ViewHolder> {
private final List<MyModel> mMyModelList;
public MyRecyclerViewAdapter(List<MyModel> myModelList) {
mMyModelList = myModelList;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_recycler, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
MyModel myModel = mMyModelList.get(position);
holder.title.setText(myModel.getTitle());
}
@Override
public int getItemCount() {
return mMyModelList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final TextView title;
public ViewHolder(View view) {
super(view);
title = (TextView) view.findViewById(R.id.tvMain);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment