我有一个带有自定义适配器的 RecyclerView,它扩展了 RecyclerView.Adapter
我在运行时使用 Textview 创建 LinearLayout 并在 RecyclerView 的每一行中对其进行膨胀
例如,RecyclerView 的第一行将在运行时创建 2 或 3 个 Textview,第二行将在运行时创建 2 或 3 个 Textview,第三行将有一些 Textview...等等...
如果我检查我的日志,它的工作几乎是完美的......但是当我向下滚动它时,它只是将一些文本视图放置在错误的位置,这意味着当我向下滚动到错误的位置时我会再次获得以前的文本视图
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
//Movie movie = mItems.get(i);
hm2 = new HashMap<String, ArrayList<PD_Data>>();
sub_rows2 = new ArrayList<PD_Data>();
hm2=categories.get(i);
String key=hm2.keySet().toArray()[0].toString();
sub_rows2=hm2.get(key);
Log.i(LOG_TKT,key);
viewHolder.textview_category.setText(key);
LayoutInflater inflater;
View new_sub_row;
for(int x=0;x<sub_rows2.size();x++){
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
new_sub_row = inflater.inflate(R.layout.recyclerview_pd, null);
TextView heading2 = (TextView)new_sub_row.findViewById(R.id.heading2);
heading2.setText(sub_rows2.get(x).sub_heading);
Log.i(LOG_TKT,sub_rows2.get(x).sub_heading);
TextView detail2 = (TextView)new_sub_row.findViewById(R.id.detail2);
detail2.setText(sub_rows2.get(x).value);
Log.i(LOG_TKT, sub_rows2.get(x).value);
viewHolder.linearlayout_recyclerview_pd.addView(new_sub_row);
}
//viewHolder.imgThumbnail.setImageResource(movie.getThumbnail());
hm2 = new HashMap<String, ArrayList<PD_Data>>();
sub_rows2 = new ArrayList<PD_Data>();
}
我究竟做错了什么 ?