Explanation:
I have a mobile application that uses the showDialog()
method at any given time, to show a DatePickerDialog
and get the date, but I see that on the following line:
showDialog(DATE_DIALOG_ID);
I have the following alert:
The method showDialog (int) from the type Activity is deprecated
It is obsolete, that is, obsolete.
Obsolete functional code:
Declaration of variables:
private int year;
private int month;
private int day;
static final int DATE_DIALOG_ID = 0;
Button btnLembrar = null;
Handler:
View.OnClickListener handler = new View.OnClickListener(){
public void onClick(View v) {
if( v.getId()==3 ){
showDialog(DATE_DIALOG_ID);
}
}
};
Assigning handler to button:
btnLembrar.setId(3);
btnLembrar.setOnClickListener(handler);
Override of event onCreateDialog()
and listener:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, datePickerListener, year, month,day);
}
return null;
}
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
util xutil=new util();
year = selectedYear;
month = selectedMonth;
day = selectedDay;
String cDta = xutil.strZero( day, 2 ) + "/" + xutil.strZero( month+1, 2 ) + "/" + xutil.strZero( year, 2 );
btnLembrar.setText(cDta);
}
};
Question:
What alternative method of performing this same operation so that it is not obsolete?