0

I'm using Android Studio w/ java and I'm programming a button to reset the values of my numeric text boxes:

et1.setText(""); //clear the first numeric text box value
et2.setText(""); //clear the second numeric text box value
tv1.setText(""); //clear the third numeric text box value
?????????????;   //here I need to select et1 (the first numeric textbox)

The question is.. how to select the et1 after clear the values ?

1
  • I am beginning programming Android so, thanks for help. Mar 13, 2021 at 12:12

1 Answer 1

0

You can focus your EditText with et1.requestFocus() and then open your keyboard with:

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
  imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
3
  • Awesome! Thanks for your answer. I'm gonna try and confirm if it works! Mar 14, 2021 at 14:14
  • Hi, et1.requestFocus() worked, and I just try it on my vitual celphone! But i the other code is showing this error: imgur.com/a/llwVCD6 .. do you know if I need to add something else? Mar 14, 2021 at 22:28
  • Yes, it's an Activity object, could be this, getContext(), getActivity(), a fragment, etc. it's the "context".
    – javdromero
    Mar 15, 2021 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.