为什么启动此适配器的活动时会触发onChekedChanged事件?如何避免这种情况?

class ScheduleAdapter extends BaseAdapter {
    SPMMainActivity   context;
    LayoutInflater    inflater;
    ArrayList<Action> actions;

    OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
            SPMManager.getSPMManager().setEnabled((Integer)buttonView.getTag() , isChecked);
            Log.d("debug","onChecked...");
            context.setNextAction();
            SPMManager.getSPMManager().update();
        }
    };
...


UPD:解决方案改用onClick

private OnClickListener checkbox_click_listener = new OnClickListener(){
        public void onClick(View v) {
            CheckBox c = (CheckBox) v ;
            SPMManager.getSPMManager().setEnabled((Integer)v.getTag() , c.isChecked());
            Log.d("onchecked","OnChecked changed");
            context.setNextAction();
            SPMManager.getSPMManager().update();
        }
    };

最佳答案

boolean isFirst = false;
    OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
            if(isFirst){
                // Put your code here
            } else
                isFirst = false;
        }
    };

07-24 20:28