ViewHolder extends RecyclerView.ViewHolder { public TextView mTextView; public ViewHolder(TextView v) { super(v); mTextView = v; } } ... @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.mTextView.setText(mDataset[position]); } ... } Made in Google ViewHolder
public MyAdapter(String[] myDataset) { mDataset = myDataset; } @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.my_text_view, parent, false); ViewHolder vh = new ViewHolder(v); return vh; } ... @Override public int getItemCount() { return mDataset.length; } } recyclerView.setAdapter(new MyAdapter()); Made in Google Adapter
public MyAdapter(String[] myDataset) { mDataset = myDataset; } @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.my_text_view, parent, false); ViewHolder vh = new ViewHolder(v); return vh; } ... @Override public int getItemCount() { return mDataset.length; } } recyclerView.setAdapter(new MyAdapter()); Made in Google recyclerView.setAdapter( new EfficientRecyclerAdapter<String>(R.layout.my_text_view, MyViewHolder.class, myDataset)); with EfficientAdapter Adapter
2”, “example 3”); // add from an array adapter.addAll(list); // add from a collection adapter.remove(“example1”); // remove element adapter.removeAt(1); // remove element at position 1 adapter.move(1, 2); // invert element 1 and 2 Auto-animated