Datepicker da o'zgartirilgan sana qanday olinadi

"Calendar.getInstance ()" dan foydalanib, joriy sanasi "DatePicker" dan birinchi marta foydalanadigan ilovani ishlab chiqayapman, keyin foydalanuvchi sana o'zgartiradi. Endi qanday qilib o'zgartirilgandan keyin yangi tarixni qanday qilib olaman?

0
foydalanuvchi sana tanlagandan tarixni tanlashni xohlaysiz.
qo'shib qo'ydi muallif RajaReddy PolamReddy, manba
Mening javobimga qarang.
qo'shib qo'ydi muallif RajaReddy PolamReddy, manba
@PolamReddyRajaReddy Ha, siz haqli va tarixchi dialog oynasidan emassiz
qo'shib qo'ydi muallif User210282, manba

2 javoblar

Buni declear.

private static final int DATE_DIALOG_ID = 0;

Ushbu kodlashni onCreate() ga qo'shing

//add a click listener to the button
    date_text.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
        }
    });

   //get the current date      
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH); 
    String da = Integer.toString(mMonth)+"/"+Integer.toString(mDay)+"/"+Integer.toString(mYear);
    date_text.setText(da);

va bu Yaratilgan ()

 private DatePickerDialog.OnDateSetListener mDateSetListener =
    new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        mYear = year;
        mMonth = monthOfYear;
        mDay = dayOfMonth;
        String selectedDate = Integer.toString(mMonth)+"/"+Integer.toString(mDay)+"/"+Integer.toString(mYear);
        date_text.setText(selectedDate);
        System.out.println("selected date is:"+selectedDate);
    }
};

@Override
protected Dialog onCreateDialog(int id)  {
    switch (id) {

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);        
    }
    return null;
}
0
qo'shib qo'ydi
Rahmat, men ushbu kodni sinab ko'rsata olaman
qo'shib qo'ydi muallif User210282, manba
Calendar cal = Calendar.getInstance();

DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener(){
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                cal.set(Calendar.YEAR, year);
                cal.set(Calendar.MONTH, monthOfYear);
                cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            }
        };
        return new DatePickerDialog(this, listener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));

Va tarixni String deb qabul qilish (Juma, 28.10.2011 15:59:59: 00: 0)

SimpleDateFormat sdfDate = new SimpleDateFormat("EEEE, d/M/yyyy HH:mm:ss:S");
String date = sdfTime.format(new Date(cal.getTimeInMillis()));
0
qo'shib qo'ydi
Ha, faqat DatePickerDialogni DatePicker uchun o'zgartiring.
qo'shib qo'ydi muallif Carnal, manba
Biroq, agar u bo'lmasa, faqat DatePickerDialog-dan foydalaning, bu eng keng tarqalgan.
qo'shib qo'ydi muallif Carnal, manba
Haqiqatan ham, agar siz quyidagilarni ko'rib chiqsangiz, SanaPicker har doim dialog bo'lib ko'rinadi: developer.android.com/resources/tutorials/views/…
qo'shib qo'ydi muallif Carnal, manba
Thanksgiving, lekin bu ham tarixiy piker bilan yaxshi ishlaydi? KodingizDialPickerDialog deb aytsa
qo'shib qo'ydi muallif User210282, manba