简体   繁体   中英

Date input from EditText

I'm trying to input date values from an editText, but i keep making error, what i should do?

    EditText DataI = (EditText) findViewById(R.id.DataI);
    EditText DataF = (EditText) findViewById(R.id.DataF);   

        calendar1.setTime(DataI);
        calendar2.setTime(DataF);

use:

SimpleDateFormat format=new SimpleDateFormat("dd/MM/yyyy");
calendar1.setTime(format.parse(DataI.getText().toString());
calendar2.setTime(format.parse(DataF.getText().toString());

There are components in Android API that're created for date-time input:

Read here

I think it's more appropriate to use the than an EditText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM