2

I am creating a program that write in EditText by barcode reader so I don't want to show the keyboard immediately even if I focused on it I don't wanna it to be visible , I need to press a button to show keyboard only to Edit sometimes . and thanks

sepp2k
  • 341,501
  • 49
  • 643
  • 658
  • I would suggest to disable that edittext when you don't want it to be editable and if the button is pressed (maybe better with checkbox) then enable the edittext. In that way the user will know that the text is editable or not. What do you think? – Blehi Aug 31 '16 at 20:41
  • Regarding the show/hide keyboard, you can check this thread: http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard – Blehi Aug 31 '16 at 20:43
  • idk sounds good but if I disable it can the barcode reader write on it ? I don't think so ... – raed ghazal Aug 31 '16 at 20:54
  • You can write it programmatically even if it is disabled. – Blehi Sep 01 '16 at 08:59

1 Answers1

0

I would disable the EditText button from the beginning:

editText.setEnabled(false);

And to answer your question, yes. Even if it is disabled, you can change the text. Disabled only means user can't change it. You can programmatically edit it.

Then when the button is pressed:

button.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        editText.setEnabled(true);
        editText.requestFocus();
    }
});

This should automatically show the keyboard when the button is pressed.

Bonus: If you want to disable the EditText once the editing is done, you can do this:

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus) {
            editText.setEnabled(false);
        }
    }
});
ᴛʜᴇᴘᴀᴛᴇʟ
  • 4,057
  • 5
  • 33
  • 62