Soft Keyboard Doesnt show when using adapter in DialogFragment

末鹿安然 提交于 2019-12-01 08:32:19

I have come across a similar problem while using a FragmentDialog containing a ListView. The items in the ListView contained EditText widgets that did not bring up the soft keyboard.

A workaround I discovered was to place an invisible EditText within the root layout of the FragmentDialog.

For example:

list_layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" />
</LinearLayout>

DialogFragment creates the views as follows:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View listLayout = inflater.inflate(R.layout.list_layout, null);
    mListView = (ListView) listLayout.findViewById(android.R.id.list);
    return new AlertDialog.Builder(getActivity()).setView(listLayout).create();
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);
    //set adapter
    mListView.setAdapter(mListAdapter);
}

Hope this helps

set block descendants property true of your list_item_layout file.. i hope it helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!