【问题标题】:Switch miss first call. Android切换未接来电。安卓
【发布时间】:2015-07-27 10:54:25
【问题描述】:

我想重建这个应用程序https://github.com/SheldonNeilson/Android-Alarm-Clock 并将CheckBox改为material Switchhttps://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;

【问题讨论】:

    标签: android uiswitch


    【解决方案1】:

    像这样尝试OnCheckedChangeListener()

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多