1

为什么在此适配器的活动开始时会触发 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();
        }
    };
4

1 回答 1

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

        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
            if(isFirst){
                // Put your code here
            } else
                isFirst = false;
        }
    };
于 2013-04-12T15:02:23.290 回答