Skip to content

Instantly share code, notes, and snippets.

@welbesw
Last active May 31, 2016 14:44
Show Gist options
  • Save welbesw/12ec600d78bf54ee73a844189dada973 to your computer and use it in GitHub Desktop.
Save welbesw/12ec600d78bf54ee73a844189dada973 to your computer and use it in GitHub Desktop.
RecyclerView.Adapter
/**
* A simple RecyclerView.Adapter class that manages items.
*/
public class ItemAdapter extends RecyclerView.Adapter<ItemHolder> {
private List<String> mItems;
public ItemAdapter(List<String> items) {
mItems = items;
}
@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
//Use a simple Android llist layout: simple_list_item_1
View view = layoutInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
//Create a holder from the inflated view and return it
return new ItemHolder(view);
}
@Override
public void onBindViewHolder(ItemHolder holder, int position) {
//Bind the item to the views via the holder
String itemString = mItems.get(position);
holder.mTextView.setText(itemString);
}
@Override
public int getItemCount() {
return mItems.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment