java – How to activate EditText

Question:

I have an EditText which, when creating an editText.setVisibility(View.GONE) hidden editText.setVisibility(View.GONE) , after which, when a certain condition is met, this text field should appear and for the cursor to blink in it, along with this, the keyboard should appear. I tried doing this, the field appears, but the cursor in it and the keyboard do not. What am I doing wrong?

@Override
public void onQuestionDialogItemClick(int which) {
    messageCompose.setVisibility(View.VISIBLE);
    etInputMsg.setEnabled(true);
    etInputMsg.setSelected(true);
}

Answer:

This will show the keyboard

InputMethodManager inputManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);

This will give focus to your EditText

etInputMsg.requestFocus();
Scroll to Top