Basic use of android-RecyleView

Add dependencies

implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'

2.Recyleiew's adapter

public class RecyleViewAdapter extends RecyclerView.Adapter<RecyleViewAdapter.RecyleViewHolder>{
    Context mContext;
    List<TextBean> beans = new ArrayList<>();

    public RecyleViewAdapter(Context mContext,List<TextBean> beans){
        this.mContext = mContext;
        this.beans.clear();
        this.beans.addAll(beans);
    }


    @NonNull
    @Override
    public RecyleViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View itemView = inflater.inflate(R.layout.item_text,null,true);
        RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        itemView.setLayoutParams(lp);

        return new RecyleViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyleViewHolder recyleViewHolder, int i) {
        recyleViewHolder.text.setText(beans.get(i).getText());
    }

    @Override
    public int getItemCount() {
        return beans.size();
    }

    class RecyleViewHolder extends RecyclerView.ViewHolder{
        private TextView text;

        public RecyleViewHolder(@NonNull View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.tv_text);
        }
    }
}

3. Call Recyleview

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<TextBean> beans = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initData();
        initAdapter();

    }

    private void initView(){
        recyclerView = findViewById(R.id.rv_recyleview);
    }

    private void initData(){
        for (int i = 0; i < 10; i++) {
            TextBean bean = new TextBean();
            bean.setText("test"+i);
            beans.add(bean);
        }
    }

    private void initAdapter(){
        RecyleViewAdapter adapter = new RecyleViewAdapter(MainActivity.this,beans);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);

    }
}

4.demo source code

5. Reference blog