在更新向上/向下滚动时,我有一个问题是更新我的回收。
我有3个(尊重视图的自定义)但我的onBindViewHolder只调用2,当我尝试按下列表时,我的列表无法正确更新它会切割(0.2秒)
我不知道为什么不能正确更新3(withtems with 3 images)
我的持有人:(为什么算上2?)但是当我失望时,算上3 ......
public class CAPusheenAdapter_Fragment_0_7 extends RecyclerView.Adapter<CAPusheenAdapter_Fragment_0_7.ViewHolder> {
private ArrayList<CustomItem_0_ALL> pusheenArrayList;
private int itemLayout;
private Context context;
DBHelper db ;
RecyclerView recyclerView;
public CAPusheenAdapter_Fragment_0_7(ArrayList<CustomItem_0_ALL> data, int itemLayout, Context context, RecyclerView recyclerView){
setHasStableIds(true);
this. pusheenArrayList = data;
this. itemLayout = itemLayout;
this. context = context;
db = new DBHelper(context);
this. recyclerView = recyclerView;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ArrayList<TextView> allTextViews;
//public TextView text1,text2,text3,text4,text5,text6,text7;
public LinearLayout l1;
public ViewHolder(View itemView) {
super(itemView);
int numOfTextViews=6;
allTextViews = new ArrayList<TextView>(); allTextViews.add(0,null);
l1 = (LinearLayout)itemView.findViewById(R.id.l1);
for(int i=1;i<=numOfTextViews;i++){
allTextViews.add(i,Config.getViewsComplext(context,itemView, "text" + i));
}
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//final int itemPosition = Fragment_0.recyclerView.getChildPosition(view); // todo SOO COOL LINE !
final int itemPosition = recyclerView.getChildPosition(view); // todo SOO COOL LINE !
//Toast.makeText(context, "No plantejada", Toast.LENGTH_SHORT).show();
//MainActivity.FragmentReutil2(new Class[]{Fragment_0_4_1.class}, 0, context);
}
});
}
}
@Override
public CAPusheenAdapter_Fragment_0_7.ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false);
Config.totalConfigFull2(context, itemLayoutView);
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
@Override
public void onBindViewHolder(CAPusheenAdapter_Fragment_0_7.ViewHolder viewHolder, int position) {
CustomItem_0_ALL pusheen = pusheenArrayList.get(position);
ArrayList<String> texts = new ArrayList<>();
texts.add(0,null);
texts.add(1,pusheen.getText1());
texts.add(2,pusheen.getText2());
texts.add(3,pusheen.getText3());
texts.add(4,pusheen.getText4());
texts.add(5,pusheen.getText5());
texts.add(6,pusheen.getText6());
for ( int i = 1 ; i < viewHolder.allTextViews.size() ; i+=1 ){
if(texts.get(i).length()>0){
viewHolder.allTextViews.get(i).setText(texts.get(i));
viewHolder.allTextViews.get(i).setVisibility(View.VISIBLE);
}else{
viewHolder.allTextViews.get(i).setVisibility(View.GONE);
}
}
//viewHolder.l1.setBackgroundResource(pusheen.getImg());
int w =Config.getWigthHeightScreen(context)[0];
int h =Config.getWigthHeightScreen(context)[1];
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(w, (int) (h/2.5));
viewHolder.l1.setBackgroundResource(pusheen.getImg());
viewHolder.l1.setLayoutParams(lp);
}
@Override
public int getItemCount() {
return this.pusheenArrayList.size();
}
}
注意:只有来自屏幕的呼叫/计数元素才会调出元素,只有在您向上/向下移动列表时才会调用