Android 我可以使用section recyclerview而不使用library section recyclerview吗?

Android 我可以使用section recyclerview而不使用library section recyclerview吗?,android,android-recyclerview,Android,Android Recyclerview,对于荷载23数据问题,我有1个RV,但我想将其分为4个数据部分,例如,A=8数据、B=5数据、C=5数据和D=5数据 我有这样的问题: public class QuestionAdapter extends RecyclerView.Adapter<QuestionAdapter.HolderData> { private List<Question> listQuestion; private Context context; private LayoutInfl

对于荷载23数据问题,我有1个RV,但我想将其分为4个数据部分,例如,A=8数据、B=5数据、C=5数据和D=5数据

我有这样的问题:

public class QuestionAdapter extends RecyclerView.Adapter<QuestionAdapter.HolderData> {

private List<Question> listQuestion;
private Context context;

private LayoutInflater inflter;
public static ArrayList<String> kdPertanyaan;
public static ArrayList<String> kdKuesioner;
public static ArrayList<String> selectedAnswers;


public QuestionAdapter(Context context, List<Question> listQuestion) {
    this.context = context;
    this.listQuestion = listQuestion;
    kdPertanyaan = new ArrayList<>();
    for (int i = 0; i < listQuestion.size(); i++) {
        kdPertanyaan.add("Nilai tidak boleh kosong");
    }
    kdKuesioner = new ArrayList<>();
    for (int i = 0; i < listQuestion.size(); i++) {
        kdKuesioner.add("Nilai tidak boleh kosong");
    }
    // initialize arraylist and add static string for all the questions
    selectedAnswers = new ArrayList<>();
    for (int i = 0; i < listQuestion.size(); i++) {
        selectedAnswers.add("Jawaban tidak boleh kosong");
    }

    inflter = (LayoutInflater.from(context));
}

public void setListQuestion(List<Question> listQuestion) {
    this.listQuestion = listQuestion;
}

@NonNull
@Override
public HolderData onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_pertanyaan,parent, false);
    HolderData holder = new HolderData(layout);
    return holder;
}

@Override
public void onBindViewHolder(@NonNull HolderData holder, @SuppressLint("RecyclerView") final int position) {
    Question question = listQuestion.get(position);
    holder.txtKdPertanyaan.setText(kdPertanyaan.set(position, question.getKd_pertanyaan()));
    holder.txtKdKuesioner.setText(kdKuesioner.set(position, question.getKd_kuesioner()));
    holder.txtNo.setText(question.getNo());
    holder.txtPertanyaan.setText(question.getPertanyaan());
    holder.question = question;
    holder.rb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // set Yes values in ArrayList if RadioButton is checked
            if (isChecked)
                selectedAnswers.set(position, "1");
        }
    });

    holder.rb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // set Yes values in ArrayList if RadioButton is checked
            if (isChecked)
                selectedAnswers.set(position, "3");
        }
    });

    holder.rb5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // set Yes values in ArrayList if RadioButton is checked
            if (isChecked)
                selectedAnswers.set(position, "5");
        }
    });

    holder.rb7.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // set Yes values in ArrayList if RadioButton is checked
            if (isChecked)
                selectedAnswers.set(position, "7");
        }
    });
}

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

class HolderData extends  RecyclerView.ViewHolder{
    @BindView(R.id.kd_pertanyaan) TextView txtKdPertanyaan;
    @BindView(R.id.kd_kuesioner) TextView txtKdKuesioner;
    @BindView(R.id.no) TextView txtNo;
    @BindView(R.id.question) TextView txtPertanyaan;
    @BindView(R.id.rbValueOf1) RadioButton rb1;
    @BindView(R.id.rbValueOf3) RadioButton rb3;
    @BindView(R.id.rbValueOf5) RadioButton rb5;
    @BindView(R.id.rbValueOf7) RadioButton rb7;

    Question question;
    HolderData(View v) {
        super(v);
        ButterKnife.bind(this, v);
    }
}
公共类QuestionAdapter扩展了RecyclerView.Adapter{ 私人名单问题; 私人语境; 私人停车场; 公共静态数组列表kdpertanyan; 公共静态数组列表kdKuesioner; 公共静态数组列表选择的答案; 公共问题适配器(上下文,列表问题){ this.context=上下文; this.listQuestion=listQuestion; kdpertanyan=newarraylist(); 对于(int i=0;i }


如何更改适配器,以便在不使用库且仅使用1个RV的情况下实现标题为4个类别A、B、C、D的recyclerview部分,这是不可能的吗?

使用recyclerview,可以使用不同的视图持有人


对于您的案例,我看到这就像是一个针对用户的测验。不是吗?可能,您需要使用ViewPager进行表格布局。在ViewPager片段中,您可以显示问题列表。用户可以在分区之间滑动。表格布局用于切换区段,还显示区段标题

你能用你给出的例子帮我更换适配器吗?我对实施它感到困惑。。。。仅适配器