问题描述
我有一个自定义DialogFragment这就是显示一个ExpandableListView及其项目的EditText。
当EditText上获得焦点的输入键盘没有显示,即使我使用InputMethodManager.FORCED标志迫使它由code。
I have a custom DialogFragment thats displays an ExpandableListView and its items are EditText.When the EditText gets the focus the input keyboard is not shown, even if I force it by code using the InputMethodManager.FORCED flag.
DialogFragment XML:
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:
Item XML of the Expanded List:
<?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:
Manifest.xml:
<activity android:windowSoftInputMode="adjustPan">
甚至迫使键盘,它也不会工作:
Even forcing the keyboard, it also does not work:
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;
}
});
任何想法,我怎么可以显示键盘?
Any idea how I can show the keyboard?
推荐答案
我发现了一个解决方法,它真的一招,因为我真的不知道为什么它的工作原理。
我只是增加了一个虚拟无形EDITTEXT在DialogFragment XML的开头:
I found a workaround, its really a trick because I don't really know why does it work.I just added a dummy invisible Edittext at the beginning of 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"
>
<EditText
android:id="@+id/dummyEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:enabled="false"
android:visibility="gone"
/>
......
这篇关于里面ExpandableListView EDITTEXT不显示键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!