Home » Android » how to scroll to next item by clicking on a checkbox in each item (recyclerview)

how to scroll to next item by clicking on a checkbox in each item (recyclerview)

Posted by: admin November 1, 2017 Leave a comment


Forgive me for my English.

My list contains 100 items. Each item consists of two checkboxes and I want to scroll to the next item each time a checkbox is clicked.

please give me the best answer link If this question has already been answered

this is my custom adapter

 public class CustomAdapter extends 
       RecyclerView.Adapter<CustomAdapter.MyViewHolder> {

private ArrayList answerFirst;
private ArrayList answerSecond;
private Context context;

public CustomAdapter(Context  context, ArrayList questionList, ArrayList 
answerFirst, ArrayList answerSecond) {
    this.context = context;
    this.answerFirst = answerFirst;
    this.answerSecond = answerSecond;

public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = 
    parent, false);
    return new MyViewHolder(v);

public void onBindViewHolder(final MyViewHolder holder, final int position) 


public int getItemCount() {
    return questionList.size();

public class MyViewHolder extends RecyclerView.ViewHolder {
    TextView question;
    CheckBox firstanswer;
    CheckBox secondanswer;
    public MyViewHolder(View itemView) {
        question = (TextView) itemView.findViewById(R.id.question_text);
        firstanswer = (CheckBox) itemView.findViewById(R.id.first_answer);
        secondanswer = (CheckBox) itemView.findViewById(R.id.second_answer);

this is the main activity

 protected void onCreate(Bundle savedInstanceState) {

    final RecyclerView recyclerView = (RecyclerView) 
    final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());

    final CustomAdapter customAdapter = new CustomAdapter(mainActivity.this, answerFirst,answerSecond);

You can do that by making the adaptor class inside the main class and in the listener method of checkbox scroll to the required position as the RecyclerView is a global variable you can access it and scroll to required position.


else pass the instance of RecyclerView in the constructor and do the same

and to get the current item position inside the adaptor by getAdapterPosition()

or you can do it with layout manager like this