我使用自定义列表视图复选框和text.Data来自服务器,如果有任何项目是可用的服务器上显示为列表view.but检查,但如果我取消选择一些项目(复选框)在滚动列表视图后再次被选中。 任何建议都会有所帮助。 这是我的适配器类:复选框再次滚动列表视图后检查
public class SetWorkAdapter extends BaseAdapter {
Context mContext;
public ArrayList<SubStkMarket> mSubStkMarkets;
checkBoxListener checkBoxListener;
ArrayList<MarketNameUID> arrayList;
public SetWorkAdapter(Context mContext, ArrayList<SubStkMarket> mSubStkMarkets,ArrayList<MarketNameUID> arrayList) {
this.mContext = mContext;
this.mSubStkMarkets = mSubStkMarkets;
this.arrayList=arrayList;
}
public interface checkBoxListener {
public void onCheckBoxClick(int position, boolean isChecked, ArrayList<MarketNameUID> mList);
}
public void setCustomButtonListner(checkBoxListener listener) {
this.checkBoxListener = listener;
}
@Override
public int getCount() {
return mSubStkMarkets.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(final int position, View view, ViewGroup viewGroup) {
View convertview;
TextView code, name;
final CheckBox checkBox;
convertview = LayoutInflater.from(mContext).inflate(R.layout.set_work_type_item, null);
code = (TextView) convertview.findViewById(R.id.set_work_type_item_market_code);
name = (TextView) convertview.findViewById(R.id.set_work_type_item_market_name);
checkBox = (CheckBox) convertview.findViewById(R.id.set_work_type_item_market_checkbox);
SubStkMarket subStkMarket = mSubStkMarkets.get(position);
checkBox.setChecked(subStkMarket.isSelected());
code.setText(String.valueOf(subStkMarket.getSubStkUID()));
name.setText(subStkMarket.getMarketName());
if(arrayList!=null)
{
for(int i=0;i<arrayList.size();i++)
{
String marketName = arrayList.get(i).getMarketName();
if(marketName.equalsIgnoreCase(subStkMarket.getMarketName()))
{
checkBox.setChecked(true);
}
}
int cnt=arrayList.size();
}
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (checkBoxListener != null) {
checkBoxListener.onCheckBoxClick(position,isChecked,arrayList);
}
}
});
return convertview;
}
}
是什么'onCheckBoxClick'的实施?你并没有改变'subStkMarket'的'selected'状态,但它不是很清楚'arraylist'是什么 – Yazan
更好地使用recyclerview –