我有一个使用recyclerview加载的问题列表,每个问题都有多个答案,我是否需要创建第二个Recyclerview来加载答案,或者有更好的方法来实现它。
这是我的代码:
`
package com.raje3.raje3.Ask;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.raje3.raje3.Browse.browseData;
import com.raje3.raje3.R;
import java.util.ArrayList;
import java.util.List;
public class AskRecyclerAdapter extends
RecyclerView.Adapter<AskRecyclerAdapter.viewHolder> {
private List<AskBrowseData> list = new ArrayList<>();
public AskRecyclerAdapter(List<AskBrowseData> list) {
this.list = list;
}
@Override
public AskRecyclerAdapter.viewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.browse_questions_item, parent, false);
return new AskRecyclerAdapter.viewHolder(view);
}
@Override
public void onBindViewHolder(AskRecyclerAdapter.viewHolder holder, int position) {
holder.q_text.setText(list.get(position).getQ_text());
holder.q_date.setText(list.get(position).getQ_date());
}
@Override
public int getItemCount() {
return list.size();
}
public static class viewHolder extends RecyclerView.ViewHolder{
TextView q_text, q_date;
public viewHolder(View itemView) {
super(itemView);
q_text = (TextView)itemView.findViewById(R.id.q_text);
q_date = (TextView)itemView.findViewById(R.id.q_date);
}
}
}
`
答案 0 :(得分:1)
我认为你必须创建动态视图, 而不是recylerView 使用scrollview作为父级并动态添加问题和答案。