-
-
Save SteveKamau72/bdca9be0605096b21fc1828a64838146 to your computer and use it in GitHub Desktop.
Simple RecyclerView Adapter
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 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