public class MainActivity extends Activity{
private RecyclerView rv;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(rv);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setAdapter(new RecyclerView.Adapter(){
class ViewHolder extends RecyclerView.ViewHolder{
private TextView tv;
public ViewHolder(TextView itemView){
super(itemView);
tv=(TextView)itemView;
}
public TextView getTv(){
return tv;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
return new ViewHolder(new TextView(parent.getContext()));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
ViewHolder vh = (ViewHolder)holder;
vh.getTv().setText("Item "+position);
}
@Override
public int getItemCount() {
return 10;
}
});
}
}