/** * Inflates an item view and returns a new view holder that contains it. * Called when the RecyclerView needs a new view holder to represent an item. * * @param parent The view group that holds the item views. * @param viewType Used to distinguish views, if more than one * type of item view is used. * @return a view holder. */ @Override public WordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // Inflate an item view. View itemView = mInflater.inflate(R.layout.wordlist_item, parent, false); return new WordViewHolder(itemView, this); }
/** * Called when RecyclerView needs a new ViewHolder of the given type to * represent an item. * * This new ViewHolder should be constructed with a new View that can * represent the items of the given type. You can either create a new View * manually or inflate it from an XML layout file. * * The new ViewHolder will be used to display items of the adapter using * onBindViewHolder(ViewHolder, int, List). Since it will be reused to * display different items in the data set, it is a good idea to cache * references to sub views of the View to avoid unnecessary findViewById() * calls. * * @param parent The ViewGroup into which the new View will be added after * it is bound to an adapter position. * @param viewType The view type of the new View. @return A new ViewHolder * that holds a View of the given view type. */ @Override public WordListAdapter.WordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // Inflate an item view. View mItemView = mInflater.inflate( R.layout.wordlist_item, parent, false); return new WordViewHolder(mItemView, this); }
/** * Called when RecyclerView needs a new ViewHolder of the given type to * represent an item. * * This new ViewHolder should be constructed with a new View that can * represent the items of the given type. You can either create a new View * manually or inflate it from an XML layout file. * * The new ViewHolder will be used to display items of the adapter using * onBindViewHolder(ViewHolder, int, List). Since it will be reused to * display different items in the data set, it is a good idea to cache * references to sub views of the View to avoid unnecessary findViewById() * calls. * * @param parent The ViewGroup into which the new View will be added after * it is bound to an adapter position. * @param viewType The view type of the new View. @return A new ViewHolder * that holds a View of the given view type. */ @Override public WordListAdapter.WordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // Inflate an item view. View mItemView = mInflater.inflate( R.layout.wordlist_item, parent, false); return new WordViewHolder(mItemView, this); }
/** * Inflates an item view and returns a new view holder that contains it. * Called when the RecyclerView needs a new view holder to represent an item. * * @param parent The view group that holds the item views. * @param viewType Used to distinguish views, if more than one * type of item view is used. * @return a view holder. */ @Override public WordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // Inflate an item view. View itemView = mInflater.inflate(R.layout.wordlist_item, parent, false); return new WordViewHolder(itemView, this); }
/** * Inflates an item view and returns a new view holder that contains it. * Called when the RecyclerView needs a new view holder to represent an item. * * @param parent The view group that holds the item views. * @param viewType Used to distinguish views, if more than one type of item view is used. * @return a view holder. */ @Override public WordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // Inflate an item view. View mItemView = mInflater.inflate(R.layout.wordlist_item, parent, false); return new WordViewHolder(mItemView, this); }
@Override public void onClick(View view) { // Get the position of the item that was clicked. int mPosition = getLayoutPosition(); // Use that to access the affected item in mWordList. String element = mWordList.get(mPosition); // Change the word in the mWordList. mWordList.set(mPosition, "Clicked! " + element); // Notify the adapter, that the data has changed so it can // update the RecyclerView to display the data. mAdapter.notifyDataSetChanged(); } }
@Override public void onClick(View view) { // Get the position of the item that was clicked. int mPosition = getLayoutPosition(); // Use that to access the affected item in mWordList. String element = mWordList.get(mPosition); // Change the word in the mWordList. mWordList.set(mPosition, "Clicked! " + element); // Notify the adapter, that the data has changed so it can // update the RecyclerView to display the data. mAdapter.notifyDataSetChanged(); } }