1
Explanation:
I have a mobile application that uses the method showDialog()
at a 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
He’s obsolete, I mean, obsolete.
Obsolete functional code:
Statement 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 the button:
btnLembrar.setId(3);
btnLembrar.setOnClickListener(handler);
Override of the event onCreateDialog()
and the Istener:
@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 operation is not obsolete?
Use
DialogFragment
– ramaral