AndroidDev
AndroidDev

Reputation: 4559

Date Picker edition of fields

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 :)

Upvotes: 1

Views: 1546

Answers (3)

Josh
Josh

Reputation: 41

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.

Upvotes: 4

PravinCG
PravinCG

Reputation: 7708

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.

Upvotes: 0

AndroidDev
AndroidDev

Reputation: 4559

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);
            }
        }
    }

Upvotes: 0

Related Questions