android - ListView 中的 EditText 失去焦点

标签 android android-listview android-edittext

<分区>

我最近遇到了这个问题,我想和你分享我的解决方案。

问题:

  • 您有一个 ListView,每行都有一个编辑文本,如下所示:

主列表.xml

<ListView
    android:id="@+id/listViewServ"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

行列表.xml

<TextView 
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"  
        android:inputType="number"/>
  • 您正在使用 TABS:tabHost 或 TabActivity。 (注意这一点非常重要)。
  • 当您单击任何列表项 EditText 时,焦点会立即移出并且您无法键入任何内容。但是键盘仍然打开。但是,由于焦点丢失,您输入的任何内容都不会出现。

现在,我将通过发布我自己的问题为您提供我的解决方案。

最佳答案

我看到一些解决方案正在使用:

android:descendantFocusability="beforeDescendants"

在布局中定义列表。

对我来说这不是必需的。使用 android:windowSoftInputMode="adjustPan"修复了这个问题:

<activity
        android:name="mainActivity"
        android:windowSoftInputMode="adjustPan"
        android:label="@string/app_name" >
    </activity>

在 Manifest.xml 中。

但是您必须确保这行代码进入您定义 TabHost 或 TabActivity 的 Activity !!!。

关于android - ListView 中的 EditText 失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17003715/

相关文章:

android - ProgressDialog 给出错误,而我在 Activity 组中的 Activity 的 onCreate() 中使用

android - 错误 : undefined reference to 'av_free_packet(AVPacket*)' when use NDK to compile ffmpeg

android - 使用Android.mk复制/系统中的多个txt文件

android - 隐藏 ListView 标题/隐藏列表中的单个分隔线

带有 LruCache 的 Android BaseAdapter 一些 ui 问题

android - 带有软键盘和 "Back"按钮的 EditText

java - 如何在单例实例中调用接口(interface)

android-listview - 在底部显示总数的 ListView

java - 检查 Android 警报对话框中的空编辑文本

android - 如何禁用 EditText 中的默认键盘,允许其他操作