android - ExpandableListView 内的 Edittext 不显示键盘

标签 android android-listview

我有一个自定义 DialogFragment,它显示 ExpandableListView,其项目是 EditText。 当 EditText 获得焦点时,即使我使用 InputMethodManager.FORCED 标志通过代码强制输入键盘也不会显示。

DialogFragment XML:

<?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:orientation="vertical"
   android:descendantFocusability="afterDescendants"
>

...

<ExpandableListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="afterDescendants"

     />

<TextView android:id="@android:id/empty"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#FF0000"
           android:text="@string/no_calculations"/>

</LinearLayout>

扩展列表的项目 XML:

<?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:padding="10dp"
   android:background="#ffffff" >
 .....

 <EditText
       android:id="@+id/editTextPercentage"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginBottom="160dp"
       android:layout_marginLeft="16dp"
       android:layout_toLeftOf="@id/percentageSymbol"
       android:inputType="numberDecimal"
       android:textColor="#000000"
       android:layout_centerVertical="true"           
       android:maxLength="8"
       android:maxLines="1"
       android:focusable="true"
   android:focusableInTouchMode="true"
       android:text="@string/default_percentage_calculations" >
 </EditText> 
 </RelativeLayout>

Manifest.xml:

<activity android:windowSoftInputMode="adjustPan">

即使强制键盘,也不起作用:

final EditText percentage=(EditText) convertView.findViewById(R.id.editTextPercentage);
percentage.setOnTouchListener(new OnTouchListener() 
{
  @Override
  public boolean onTouch(View v, MotionEvent event) {
     InputMethodManager imm = (InputMethodManager)  getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
   imm. showSoftInput (percentage, InputMethodManager. SHOW_FORCED);
   return false;
}
      });

知道如何显示键盘吗?

最佳答案

我找到了一个解决方法,这确实是一个技巧,因为我真的不知道它为什么有效。 我刚刚在 DialogFragment XML 的开头添加了一个虚拟的不可见 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:orientation="vertical"
    android:descendantFocusability="afterDescendants"
>

<EditText
       android:id="@+id/dummyEditText"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:inputType="numberDecimal"            
        android:enabled="false"
        android:visibility="gone"
       />
......

关于android - ExpandableListView 内的 Edittext 不显示键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23941206/

相关文章:

android - Listview 拉动刷新库并添加标题 View

android - SwipeRefreshLayout 隐藏在带有透明状态栏的 ActionBar 后面

android - 如何使用前一个 fragment 的 EditText 输入更改 fragment 中的 TextView?

java - 白屏和崩溃-Android Studio

java - 当JSON文件没有任何且只有获取对象时如何创建数组

android - 访问@android :id/list ListView from code

android - 如何检查listitem是否在listview android中被选中?

android - 如何排除显示最近应用程序的我的应用程序屏幕截图

android - 无法在android中获取json数组

android - 在现有 ListVIew 中添加更多项目时 ImageView 重叠