mercredi 9 août 2017

Check box again get checked after scroll listview

I am using custom list view for checkbox and text.Data is come from server and if any item is available on server it is showing as checked in list view.but if i deselect some of item(checkbox) it is again get selected after scroll list view. Any suggestion will be helpful. This is my adapter class :

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;
    }


    }




Aucun commentaire:

Enregistrer un commentaire