0

Why showdialog() in the following code shows "The method showDialog(int) from the type Activity is deprecated"?

        Button b=(Button)findViewById(R.id.button1);
        b.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
            showDialog(DATE_PICKER_ID); 
                Date d=new Date();
                //d.getMinutes();
                Toast.makeText(getApplicationContext(), ""+d, Toast.LENGTH_LONG).show();
            }
        });
Bruce
  • 8,609
  • 8
  • 54
  • 83

4 Answers4

1

Because showDialog(int id) method is deprecated. Try to implement DialogFragment Default android date picker.

M D
  • 47,665
  • 9
  • 93
  • 114
0

As you've said, the method has been deprecated. Fragment based dialogs are preferred now. Please see the DialogFragment class.

Anid Monsur
  • 4,538
  • 1
  • 17
  • 24
0
// try this way
final Calendar date = Calendar.getInstance();
DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

            }
        }, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE));

dateDialog.show();
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
0

showdialog() method is deprecated.Try to follow this tutorial.

Neha Agarwal
  • 622
  • 7
  • 24