android - 在键盘关闭时删除由 ListView 行托管的 EditText 中添加的文本

标签 android

我使用以下 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/

相关文章:

android - 从服务器获取的数据在房间数据库中复制了多次

java - 从 Android Studio 3.3 升级后,Android Studio 3.4 在加载项目时卡住

android - SocketTimeoutException 安卓

android - Android Studio 中的 "Failed to get the compiler information for file ..."

java - Bundle 丢失两个 Activity 之间的所有数据

android - 如何在我的 Android 应用程序本身中使用 Mockito?我收到 Hamcrest 依赖冲突,当它仅用于测试时我没有收到

android - 工具栏字幕被剪切(不适合高度)

android - 如何在每个选项卡下添加 Activity ?

android - 三星 Galaxy J1 4G 上的 webRTC 应用程序崩溃

android - 具有不同 Min SDK 级别的 Instant App Installable App