Android 是否有任何 API 来提供日期时间作为用户的输入(startActivityForResult)? [英] Has Android any API to provide Date-time as input from user (startActivityForResult)?
问题描述
我正在寻找提供用户定义的日期时间信息的 API.我在过去的联系人列表中使用过:
I'm looking for API that provide Date-time info defined by user. I used in the past Contact List like:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
((Activity) mContext).startActivityForResult(intent, LauncherUI.RESULT_GOT_CONTACT_INFO);
并在 onActivityResult
上使用
Uri contactData = intent.getData();
//Cursor cursor = managedQuery(contactData, null, null, null, null);
Cursor cursor = cr.query(contactData, null, null, null, null);
cursor.moveToFirst();
String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
String id = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
我可以提取姓名、电话和gmail.
现在我的目标是对格式为 YYYY-MM-DD hh:mm:ss 的日期时间做同样的事情.类似的东西:
Now my aim to do the same for Date-time with format YYYY-MM-DD hh:mm:ss. Something like:
我不想自己实现它,因为这个功能存在(仅在没有 API 的情况下)
I don't want to implement it by myself since this feature exists (only in case if no API)
有什么想法吗?
推荐答案
是的,Android 有内置的日期和时间选择器对话框,参见 this 文章了解详情(它使用片段,但您可以简单地使用 DatePickerDialog & TimePickerDialog).
Yes, Android has built-in date and time picker dialogs, see this article for details (it uses fragments but you can use simply DatePickerDialog & TimePickerDialog).
您还可以将其他开源库与酷炫的数据选择器一起使用:
You can also use other open source libraries with a cool data picker:
- https://code.google.com/p/android-dateslider/
- https://code.google.com/p/android-wheel/
- https://code.google.com/p/scroll-picker-view-for-android/
- ...
(使用 Android UI 模式应用 https://play.google.com/store/apps/details?id=com.groidify.uipatterns&hl=es 找到这样的库)
(Use Android UI patterns app https://play.google.com/store/apps/details?id=com.groidify.uipatterns&hl=es to find libraries like these)
这篇关于Android 是否有任何 API 来提供日期时间作为用户的输入(startActivityForResult)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!