Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.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
Android 避免EditText使用click事件_Android_Onclick_Android Edittext - Fatal编程技术网

Android 避免EditText使用click事件

Android 避免EditText使用click事件,android,onclick,android-edittext,Android,Onclick,Android Edittext,通常,将可聚焦,可聚焦InTouch+可点击设置为false就足够了。但在这里它不起作用 我希望父级LinearLayout也使用对EditText的单击,但它不起作用 <LinearLayout android:id="@+id/llText" android:layout_width="0dp" android:layout_weight="1" android:background="?attr/selectableItemBackground"

通常,将
可聚焦
可聚焦InTouch
+
可点击
设置为false就足够了。但在这里它不起作用

我希望父级
LinearLayout
也使用对
EditText
的单击,但它不起作用

<LinearLayout
    android:id="@+id/llText"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:background="?attr/selectableItemBackground"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tvText"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:paddingRight="5dp"
        android:text="@null" />

    <EditText
        android:id="@+id/etText"
        android:inputType="none"
        android:gravity="center_horizontal"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:layout_width="wrap_content"
        android:ems="4"
        android:layout_gravity="center_vertical"
        android:layout_height="wrap_content" />

</LinearLayout>

我尝试了
editable=false
inputType=none
,但不起作用。为什么不呢?
EditText
会使用单击,而不会将其交给其父项

编辑


我正在将一个
onClickListener
设置为
线性布局
,如果我直接按
编辑文本

,它将不起作用。

您应该使用ViewGroup.onInterceptTouchEvent(MotionEvent)

此方法用于拦截所有触摸屏运动事件


很晚了,但可能有人需要这些信息。 将focusableInTouch+clickable设置为false后,将其添加到java代码中:

    editText.setMovementMethod(null);
    editText.setKeyListener(null);
不要忘记保存这些值,以便以后恢复:

    mMovementMethod = mEditText.getMovementMethod();
    mKeyListener = mEditText.getKeyListener();

您是否尝试过在线性布局上使用android:clickable=“true”?是的,我正在为它设置一个
onClickListener
。。。只要我不按
编辑文本
,它就可以工作。我更喜欢使用
文本视图
,并将其样式设置为
编辑文本
。。。尽管如此,我还是感兴趣的是,为什么上面的解决方案在任何地方都可以使用,但使用的是
EditText
…在还原侦听器之后,EditText将不适用于我,直到我将
focusableInTouchMode
设置为true