开发者

Date Picker edition of fields

开发者 https://www.devze.com 2023-04-09 03:01 出处:网络
Is it possible to disable the edition of fields in DatePicker? Indeed when I touch on the editable box in the DatePicker, the keyboard

Is it possible to disable the edition of fields in DatePicker? Indeed when I touch on the editable box in the DatePicker, the keyboard appears, and 开发者_开发问答I don't want this.

Someone have an idea?

Thanks a lot for your response :)


This is actually really easy. Just use

datePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);

The NumberPickers will never receive the focus when they are tapped and the soft input keyboard should not appear. I have been using this method on API level 7 with success.


Yeh i got the answer..the thing we need to do is...

    DatePicker m_dtPicker  = (DatePicker) findViewById(R.id.dt_picker);
    setDisabledTextViews(m_dtPicker);


    private void setDisabledTextViews(ViewGroup dp) 
    {
        for (int x = 0, n = dp.getChildCount(); x < n; x++) 
        {
            View v = dp.getChildAt(x);

            if (v instanceof TextView) 
            {
                v.setEnabled(false);
            } 
            else if (v instanceof ViewGroup) 
            {
                 setDisabledTextViews((ViewGroup)v);
            }
        }
    }


This should not be done. DatePicker has that functionality specifically to allow users convenient option instead of tapping/holding +/-

What you are trying to achieve is the iOS for of Picker which although looks nice but really is inconvenient on Android.

0

精彩评论

暂无评论...
验证码 换一张
取 消