Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何编写代码,让用户不选择任何内容或选择时间?_Java_Android_Firebase - Fatal编程技术网

Java 如何编写代码,让用户不选择任何内容或选择时间?

Java 如何编写代码,让用户不选择任何内容或选择时间?,java,android,firebase,Java,Android,Firebase,我想从edittext中为用户编写两个选项,要么不输入任何内容(这意味着不需要设置提醒日期),要么通过datePickerDialog选择一个时间来提醒。我如何实现 这是我的edittextaddtime代码: addtime.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { d

我想从
edittext
中为用户编写两个选项,要么不输入任何内容(这意味着不需要设置提醒日期),要么通过
datePickerDialog
选择一个时间来提醒。我如何实现

这是我的
edittext
addtime代码:

addtime.setOnTouchListener(new View.OnTouchListener() {
       @Override
       public boolean onTouch(View v, MotionEvent event) {
           datePickerDialog.show();
           return false;
       }
   });

将此edittextunfocused.xml放入drawable文件夹

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" 
xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:color="@color/grey"
    android:width="@dimen/twoDp"/>
<corners android:radius="@dimen/twoDp"></corners>
</shape>

把这个放在编辑文本的地方

<EditText
 android:layout_width="match_parent"                   
 android:layout_height="match_parent"
 android:background="@drawable/edittextunfocused"
 android:text="Add Time"
 android:id="@+id/addtime"

                    />


最好使用textview将edittext的背景设置为灰框或灰线,并将起始文本设置为日期,然后单击“打开日期选择器”dialogue@ApoorvSingh你能说得详细些吗?对不起,我是初学者。所以你不知道如何在
EditText
上初始化
datePickerDialog
?@EJusius是的,我知道。