我使用以下 GUI 设置:
- ListView Activity
- 提供此列表的 CursorAdapter
- Activity 布局
ListView 中行的布局:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity = "right" > <TextView android:id="@+id/text_9_description_top" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:layout_alignParentLeft="true"> </TextView> <CheckBox android:id="@+id/chkApprovedTabChapter9" android:layout_toRightOf="@+id/text_9_description_top" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="right" > </CheckBox> <Button android:id="@+id/tabchaprter9_row_button_delete" android:layout_height="wrap_content" android:text="leftBtn" android:layout_width="wrap_content" android:background="@android:drawable/ic_menu_delete" android:layout_toRightOf="@+id/chkApprovedTabChapter9" > </Button> <Button android:id="@+id/tabchaprter9_row_button_edit" android:layout_width="wrap_content" android:layout_toRightOf="@+id/tabchaprter9_row_button_delete" android:text="rightBtn" android:layout_height="match_parent" android:background="@android:drawable/ic_menu_edit"> </Button> <EditText android:layout_width="wrap_content" android:id="@+id/text_9_description_bottom" android:layout_toRightOf="@+id/tabchaprter9_row_button_edit" android:layout_height="match_parent" android:gravity="right" android:layout_alignParentRight ="true" android:inputType="text" android:imeOptions="normal"> </EditText> </RelativeLayout>
行布局包含 EditText、复选框和几个按钮。 ListView是用setAdapter()填充的。显然 ListView 已正确创建,我看到所有包含数据的行。
第一个问题:我想最初将 EditText 显示为禁用状态,这样用户就无法立即编辑文本。只有在单击行中的“编辑”按钮后,EditText 才可用于输入。设置启用“false”对 EditText 没有影响(在代码和 XML 属性中尝试过 bot)EditText 始终是可编辑的。
第二个问题:使用软键盘在 EditText 中键入看起来不错 - 我看到所有更改,但是当我关闭软键盘时(按 Android 后退按钮或键盘上的“隐藏”按钮)所有添加的文本都被删除并且 EditText 恢复为初始状态阶段。
最佳答案
与其启用和禁用它,不如尝试使用 focussable= "false"
这将产生理想的效果。
关于android - 在键盘关闭时删除由 ListView 行托管的 EditText 中添加的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6814211/