我是android的新手,我一直在从事一个项目,并且在我的新闻提要页面中,我尝试包括一个模块化提要RecyclerView,该提要显示具有不同答案形式的问题,并根据Question类型进行变化。到目前为止,我这样做的方法是使用include并在需要时将表单显示为可见。最近,由于我添加了更多模块,因此该应用开始明显减速,因此我尝试实现ViewStubs。
这是我的RecyclerView适配器:
public class ReQuestionAdapter extends RecyclerView.Adapter<FeedItem> {
private ArrayList<Question> myQuestions;
public ReQuestionAdapter(Context context, ArrayList<Question> questions) {
myQuestions = questions ;
}
@Override
public FeedItem onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_re_question, parent, false);
return new FeedItem(view);
}
@Override
public void onBindViewHolder(FeedItem holder, int position) {
Question q = myQuestions.get(position);
holder.bindQuestion(q);
}
@Override
public int getItemViewType(int position) {
return 0;
}
@Override
public int getItemCount() {
return myQuestions.size();
}
}
Run Code Online (Sandbox Code Playgroud)
这是适配器的ViewHolder类:
public class FeedItem extends RecyclerView.ViewHolder{
private …Run Code Online (Sandbox Code Playgroud) data-binding android viewstub android-viewholder android-recyclerview