【发布时间】:2014-08-10 19:35:51
【问题描述】:
我创建了自定义ListView,它有两个TextViews、两个Buttons和一个EditText,
我的问题是:
1) 编辑文本即使在添加后也会失去控制 android:descendantFocusability="beforeDescendants"
到根布局和 beforeDescendants 块的 onItemClick 和 onClick 按钮
2) 如果我在根布局中添加android:descendantFocusability="BlocksDescendants",则列表的 onItemClick 和按钮的 onClick 开始工作,但 EditText 变得不可触摸,即使在触摸 edittext 键盘后也不显示。
有人可以指导我吗?
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_separator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/dark_grey"
android:paddingLeft="15dp"
android:text="TextView"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/lighter_gray"
android:paddingLeft="15dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_detail_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/tv_detail_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:paddingBottom="5dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<ImageButton
android:id="@+id/btn_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="1dp"
android:src="@drawable/right_arrow" />
<EditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="@drawable/edittext_background"
android:enabled="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="textPersonName" >
</EditText>
<ImageButton
android:id="@+id/btn_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="1dp"
android:src="@drawable/left_arrow" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
使用您尝试过的代码更容易理解问题。
-
你无法专注于edittext 使用这个属性android:focusableInTouchMode="true"
-
尝试将这个:android:descendantFocusability="beforeDescendants" 替换成这个:android:focusable="false", android:focusableInTouchMode="false"
-
Haresh 我已经尝试过了,但是发生了什么是 EditText 被点击了,但我输入的任何内容都没有反映在 EditText 中它失去控制
标签: android listview android-listview android-edittext android-button