0
I have the following method implemented and I will use it in various Activities
private int dia, mes, ano;
String data;
String dd, mm;
int hora, minuto;
static final int TIME_DIALOG_ID = 0;
String horas;
@Override
public void onCreate(Bundle savedInstaceState){
super.onCreate(savedInstaceState);
setContentView(R.layout.sub_casa_quarto);
Calendar c = Calendar.getInstance();
ano = c.get(Calendar.YEAR);
mes = c.get(Calendar.MONTH);
dia = c.get(Calendar.DAY_OF_MONTH);
hora=c.get(Calendar.HOUR);
minuto=c.get(Calendar.MINUTE);
if (mes >=1 && mes<10){
mm = "0"+String.valueOf(mes);
}
else
mm = String.valueOf(mes);
if (dia>= 1 && dia<10){
dd = "0"+String.valueOf(dia);
}
else
dd = String.valueOf(dia);
data = String.valueOf(ano) + "-" + mm + "-"+dd;
}
//Data
public void onCLickteste(View v){
final DatePickerDialog dialogo = new DatePickerDialog(this, mDataSetListener, ano, mes, dia);
dialogo.show();
}
private OnDateSetListener mDataSetListener = new OnDateSetListener(){
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth){
int a = year;
int m = monthOfYear;
int d = dayOfMonth;
if (m >= 1 && m<10){
mm = "0"+String.valueOf(m);
}else
mm = String.valueOf(m);
if (d>=1 && d<10){
dd = "0" + String.valueOf(d);
}else
dd = String.valueOf(d);
data = String.valueOf(ano) + "-" +mm+ "-" +dd;
mostrarData();
}
};
private void mostrarData(){
Toast.makeText(this, "Data Selecionada" + data,Toast.LENGTH_LONG).show();
}
I would like to create a class and put it there so I don’t have to repeat the code. Could someone help me or explain how to do this? I need the return (result) to save to the database.
You can use
Fragments
to do this. See this post– ramaral