Android TimePicker AM/PM button not invoking onTimeChanged

前端 未结 11 1121
半阙折子戏
半阙折子戏 2021-02-05 12:38

I\'m having some issues implementing a TimePicker in my application that allows the user to change the time of a database record prior to inserting it.

The problem is th

11条回答
  •  礼貌的吻别
    2021-02-05 13:21

    this link shows that onTimeChanged(); is getting called which triggers the event dispatcher.

    If you're not getting the events you need (even though it appears to be sending) you have have to

    • extend the default TimerPicker,

    • override mAmPmButton.setOnClickListener,

    • and include your version in the view.


    mAmPmButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                requestFocus();
                if (mIsAm) {
    
                    // Currently AM switching to PM
                    if (mCurrentHour < 12) {
                        mCurrentHour += 12;
                    }                
                } else {
    
                    // Currently PM switching to AM
                    if (mCurrentHour >= 12) {
                        mCurrentHour -= 12;
                    }
                }
                mIsAm = !mIsAm;
                mAmPmButton.setText(mIsAm ? mAmText : mPmText);
                onTimeChanged();
            }
        });
    

提交回复
热议问题