切换未接来电。 Android的

时间:2015-07-27 10:54:26

标签: android uiswitch

我想重建这个应用https://github.com/SheldonNeilson/Android-Alarm-Clock 并将CheckBox更改为材料Switch https://github.com/navasmdc/MaterialDesignLibrary

设置OnCheckListener。 我的问题。当我开始应用程序。而CheckOn有些报警,onCheckListener错过了这个第一个电话。之后,他们正常工作。

如果第一次行动CheckOff - 没问题。 如果我想打开闹钟,第一次通话时会出现问题。

请睁开眼睛。

@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    if (null == view)
        view = LayoutInflater.from(alarmActivity).inflate(
                R.layout.alarm_list_element, null);

    final Alarm alarm = (Alarm) getItem(position);

    final Switch checkBox = (Switch) view.findViewById(R.id.switch_alarm_active);
     checkBox.setChecked(alarm.getAlarmActive());
     checkBox.setTag(position);
     //checkBox.setOnClickListener(alarmActivity);
    checkBox.setOncheckListener(new Switch.OnCheckListener() {
        @Override
        public void onCheck(Switch aSwitch, boolean b) {
            Toast.makeText(alarmActivity.getApplicationContext(), "onClick " + b, Toast.LENGTH_SHORT).show();
            alarm.setAlarmActive(b);
            Database.update(alarm);
            alarmActivity.callMathAlarmScheduleService();
            if (b) {
                Toast.makeText(alarmActivity.getApplicationContext(), alarm.getTimeUntilNextAlarmMessage(), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(alarmActivity.getApplicationContext(), "Off", Toast.LENGTH_SHORT).show();
            }
        }
    });


    TextView alarmTimeView = (TextView) view
            .findViewById(R.id.textView_alarm_time);
    alarmTimeView.setText(alarm.getAlarmTimeString());


        TextView alarmDaysView = (TextView) view
                .findViewById(R.id.textView_alarm_days);
        alarmDaysView.setText(alarm.getRepeatDaysString());


    return view;

1 个答案:

答案 0 :(得分:0)

尝试这样的OnCheckedChangeListener()

     checkBox.setOnCheckedChangeListener(
                new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
                        //Do something..
                    }
                }
    );