Soft Keyboard Doesnt show when using adapter in DialogFragment

前端 未结 2 1072
栀梦
栀梦 2021-01-14 12:57

I have a custom DialogFragment which has an ArrayAdapter in it which has some editTexts in it. When the dialog is shown the soft keyboard does not appear even if i press on

相关标签:
2条回答
  • 2021-01-14 13:14

    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

    0 讨论(0)
  • 2021-01-14 13:25

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

    0 讨论(0)
提交回复
热议问题