Pick up show and change Time / Date

Asked

Viewed 2,580 times

-1

Good morning! I would like to take the time of mobile play on the screen so the user can change and save the time the user chooses and the same thing for the date. example to do like the alarm clock

1 answer

2


I solved my problem with that code!

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();
}    public void onClickData(View v){
    final DatePickerDialog dialogo = new DatePickerDialog(this, mDataSetListener, ano, mes, dia);
    dialogo.show();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.