1
I would like to know but the funny thing is that I ran here and it worked even saying that it is obsolete. What should I do?
private Button botao;
static final int DATE_DIALOG_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_date_pick);
botao = (Button) findViewById(R.id.button);
botao.setOnClickListener(this);
}
@Override
protected Dialog onCreateDialog(int id) {
Calendar calendario = Calendar.getInstance();
int ano = calendario.get(Calendar.YEAR);
int mes = calendario.get(Calendar.MONTH);
int dia = calendario.get(Calendar.DAY_OF_MONTH);
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, ano, mes,
dia);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
String data = String.valueOf(dayOfMonth) + " /"
+ String.valueOf(monthOfYear+1) + " /" + String.valueOf(year);
Toast.makeText(getApplicationContext(),
"DATA = " + data, Toast.LENGTH_SHORT)
.show();
}
};
@Override
public void onClick(View v) {
if (v == botao)
showDialog(DATE_DIALOG_ID);
}