MyTetra Share
Делитесь знаниями!
MyAdapter.java
22.04.2017
11:24
Раздел: Android - Ресурсы - developer.android.com - API Guides - Создание списков и карточек
MyAdapter.java

MyAdapter.java

package com.example.rt.recycler; 
 
import android.support.v7.widget.RecyclerView; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 
 
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { 
    private String[] mDataset; 
 
 
    // Provide a reference to the views for each data item 
    // Complex data items may need more than one view per item, and 
    // you provide access to all the views for a data item in a view holder 
    public static class ViewHolder extends RecyclerView.ViewHolder { 
        // each data item is just a string in this case 
        public TextView mTextView; 
        public ViewHolder(View v) { 
            super(v); 
            mTextView = (TextView) v.findViewById(R.id.textV); 
 
        } 
    } 
 
    // Provide a suitable constructor (depends on the kind of dataset) 
    public MyAdapter(String[] myDataset) { 
        mDataset = myDataset; 
    } 
 
    // Create new views (invoked by the layout manager) 
    @Override 
    public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, 
                                                   int viewType) { 
        // create a new view 
        View v = LayoutInflater.from(parent.getContext()) 
                .inflate(R.layout.item, parent, false); 
        // set the view's size, margins, paddings and layout parameters 
 
        ViewHolder vh = new ViewHolder(v); 
        return vh; 
    } 
 
    // Replace the contents of a view (invoked by the layout manager) 
    @Override 
    public void onBindViewHolder(ViewHolder holder, int position) { 
        // - get element from your dataset at this position 
        // - replace the contents of the view with that element 
        holder.mTextView.setText(mDataset[position]); 
 
    } 
 
    // Return the size of your dataset (invoked by the layout manager) 
    @Override 
    public int getItemCount() { 
        return mDataset.length; 
    } 
 
 
} 
 
 

 
MyTetra Share v.0.52
Яндекс индекс цитирования