Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I launch the soft keyboard after "Cancel" button is clicked in DialogFragment?

Fragment.java file:

....
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.skyfrag_layout, container, false);
    getDialog().setTitle("Delete skycard");
    Button btnCancel = (Button) rootView.findViewById(R.id.btnCancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
          getDialog().cancel();
        }
    });
...

I tried each of the below in the onClick function but neither worked.

1) getDialog().getWindow().setSoftInputMode( LayoutParams.SOFT_INPUT_STATE_VISIBLE);

2)InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

like image 287
AJW Avatar asked Jan 29 '26 16:01

AJW


1 Answers

I guess that you are trying to show the keyboard again because you have a widget that needs editing once your dialog is closed.

Have you tried calling showSoftInputFromInputMethod (IBinder token, int flags) instead of toggleSoftInputFromWindow ? See the doc here. (Note: the IBinder can be obtained by yourView.getWindowToken())

Hope this helps.

like image 178
k3v1n4ud3 Avatar answered Feb 01 '26 09:02

k3v1n4ud3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!