Soft Keyboard Doesnt show when using adapter in DialogFragment

前端 未结 2 1071
栀梦
栀梦 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:

    
    
        
    
        
    
    

    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

提交回复
热议问题