如果在水平回收视图中,则不检测不可见的项目值
Not detecting invisible item values if it is in horizontalrecyclerview
我有我的滚动视图项目,从周日到周六水平,带有复选框,在移动视图中,如果我滚动,它显示周日到周六,如果不滚动,它显示周日到周三,
当我更新我的订阅时,它需要从星期日到星期三的值,剩余的值不会出现它们作为空值出现我该怎么办?
这是我的 adapterclass
代码:
public class SubscriptionRecyclerViewAdapter extends RecyclerView.Adapter<SubscriptionRecyclerViewAdapter.MyViewHolder> {
private List<DaysOfDelivery> daysOfDeliveryList;
public static String[] daylist;
public class MyViewHolder extends RecyclerView.ViewHolder {
CheckBox checkBox;
TextView textViewPrice;
public MyViewHolder(View view) {
super(view);
checkBox = (CheckBox) view.findViewById(R.id.deliveryname_checkbox);
textViewPrice = (TextView) view.findViewById(R.id.period_price);
}
}
public SubscriptionRecyclerViewAdapter(List<DaysOfDelivery> daysDeliveryList) {
this.daysOfDeliveryList = daysDeliveryList;
daylist = new String[daysOfDeliveryList.size()];
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.horizontal_listview_availability, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
DaysOfDelivery days = daysOfDeliveryList.get(position);
holder.checkBox.setText(days.getAvailabilityDays());
holder.checkBox.setChecked(days.getCheckbox());
holder.textViewPrice.setText(days.getPrice());
if (days.getCheckbox())
daylist[position]="1";
else
daylist[position]="0";
}
@Override
public int getItemCount() {
return daysOfDeliveryList.size();
}
}
和我的 activity class 更新功能:
update1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] days= SubscriptionRecyclerViewAdapter.daylist;
if(isConnected)
new EditSubscription().execute();
else
Toast.makeText(Subscription.this, "No Internet Connection", Toast.LENGTH_LONG).show();
}
});
这几天我只得到星期天到星期三的值,剩下的不会来
在您的 activity/fragment
中维护 daylist
数组,当您想从适配器更新该列表时使用回调进行更新。
在屏幕中不可见的 recyclerView 视图,在进入屏幕之前不会被初始化。
或者在构造函数中也初始化该列表:
public SubscriptionRecyclerViewAdapter(List<DaysOfDelivery> daysDeliveryList) {
this.daysOfDeliveryList = daysDeliveryList;
daylist = new String[daysOfDeliveryList.size()];
for (int i = 0; i < daysDeliveryList.size(); i++) {
daylist[i] = daysDeliveryList.get(i).getCheckbox() ? "1" : "0";
}
}
我有我的滚动视图项目,从周日到周六水平,带有复选框,在移动视图中,如果我滚动,它显示周日到周六,如果不滚动,它显示周日到周三,
当我更新我的订阅时,它需要从星期日到星期三的值,剩余的值不会出现它们作为空值出现我该怎么办?
这是我的 adapterclass
代码:
public class SubscriptionRecyclerViewAdapter extends RecyclerView.Adapter<SubscriptionRecyclerViewAdapter.MyViewHolder> {
private List<DaysOfDelivery> daysOfDeliveryList;
public static String[] daylist;
public class MyViewHolder extends RecyclerView.ViewHolder {
CheckBox checkBox;
TextView textViewPrice;
public MyViewHolder(View view) {
super(view);
checkBox = (CheckBox) view.findViewById(R.id.deliveryname_checkbox);
textViewPrice = (TextView) view.findViewById(R.id.period_price);
}
}
public SubscriptionRecyclerViewAdapter(List<DaysOfDelivery> daysDeliveryList) {
this.daysOfDeliveryList = daysDeliveryList;
daylist = new String[daysOfDeliveryList.size()];
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.horizontal_listview_availability, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
DaysOfDelivery days = daysOfDeliveryList.get(position);
holder.checkBox.setText(days.getAvailabilityDays());
holder.checkBox.setChecked(days.getCheckbox());
holder.textViewPrice.setText(days.getPrice());
if (days.getCheckbox())
daylist[position]="1";
else
daylist[position]="0";
}
@Override
public int getItemCount() {
return daysOfDeliveryList.size();
}
}
和我的 activity class 更新功能:
update1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] days= SubscriptionRecyclerViewAdapter.daylist;
if(isConnected)
new EditSubscription().execute();
else
Toast.makeText(Subscription.this, "No Internet Connection", Toast.LENGTH_LONG).show();
}
});
这几天我只得到星期天到星期三的值,剩下的不会来
在您的 activity/fragment
中维护 daylist
数组,当您想从适配器更新该列表时使用回调进行更新。
在屏幕中不可见的 recyclerView 视图,在进入屏幕之前不会被初始化。
或者在构造函数中也初始化该列表:
public SubscriptionRecyclerViewAdapter(List<DaysOfDelivery> daysDeliveryList) {
this.daysOfDeliveryList = daysDeliveryList;
daylist = new String[daysOfDeliveryList.size()];
for (int i = 0; i < daysDeliveryList.size(); i++) {
daylist[i] = daysDeliveryList.get(i).getCheckbox() ? "1" : "0";
}
}