Last active
May 31, 2016 14:44
-
-
Save welbesw/12ec600d78bf54ee73a844189dada973 to your computer and use it in GitHub Desktop.
RecyclerView.Adapter
This file contains hidden or 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
/** | |
* 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