-1

In my application I'am just calling DatePicker when i click the EditText.

But when I test this, first it ask us to edit and if I again click that then it will show the DatePicker.

I want to show only DatePicker without editable.

shkschneider
  • 17,833
  • 13
  • 59
  • 112
user3764346
  • 129
  • 2
  • 5
  • 15

5 Answers5

1

put this 2 lines in your edittext xml code

 android:focusable="false"
 android:focusableInTouchMode="false"
Ravi
  • 34,851
  • 21
  • 122
  • 183
1
private DatePickerDialog.OnDateSetListener pickerListener =
                   new DatePickerDialog.OnDateSetListener() {

    // when dialog box is closed, below method will be called.

    @Override
    public void onDateSet(DatePicker view, int selectedYear,
            int selectedMonth, int selectedDay) {

        year = selectedYear;
        month = selectedMonth;
        day = selectedDay;

        ArrivalDate = new Date(year - 1900, month, day);

        textArrivalDate.setText(new StringBuilder().append(month + 1)
                    .append("/").append(day).append("/").append(year)
                    .append(""));
    }
};

Use the following code block with on TextView Click event:

Calendar c = Calendar.getInstance();
datePickerDialog = new DatePickerDialog(this, pickerListener,
                    c.get(Calendar.YEAR), c.get(Calendar.MONTH),
                    c.get(Calendar.DAY_OF_MONTH));
datePickerDialog.SetTitle("Select date");
datePickerDialog.show();
Waqas Raja
  • 10,802
  • 4
  • 33
  • 38
Prashant Jajal
  • 3,469
  • 5
  • 24
  • 38
1

try this. by adding these lines to edittext

android:inputType="none"
android:clickable="true"
android:focusable="false"

and in onclick do wat u want.

M S Gadag
  • 2,057
  • 1
  • 12
  • 15
0

Don't use an EditText then.

An EditText is meant to let the user input text using a keyboard...

Use a clickable TextView, or a kind of Button instead.

shkschneider
  • 17,833
  • 13
  • 59
  • 112
0

simplest way to do this use setOnFocusChangeListener instead of OnCLickListner following code is an example which i am using for same purpose.

editText_dob.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if(hasFocus){
            hideSoftKeyboard(RegisterationActivity.this);
            editText_dob.setRawInputType(InputType.TYPE_CLASS_TEXT);
            setDate(editText_dob);
        }
    }
}); 
Shafqat Jamil Khan
  • 1,039
  • 1
  • 9
  • 17