samedi 9 mai 2015

Focus and Cursor Issues with EditText

Right now I have a fragment with a ScrollView that contains a RelativeLayout, that contains a CardView, that contains several EditText children from the rey5137 Material library.

For a few of these EditText children, I want to be able to follow this workflow:

  1. Click on the EditText and see my keyboard and cursor appear
  2. Type whatever
  3. Press Enter and have the keyboard/cursor disappear,
  4. Repeat as desired

I've tried making it so that I set an OnClickListener for my EditText that setCursorVisible(true), and an OnEditorActionListener that listened for a KeyEvent.KEYCODE_ENTER to hide the soft keyboard and setCursorVisible(false).

And with that, now it goes like this:

  1. Click EditText field, floating label goes up, cursor is visible, keyboard is visible
  2. Type stuff
  3. Press enter, keyboard disappears, cursor disappears, one extra space character is added (I'd ideally like to not have that too?)
  4. Click EditText field, cursor is not visible, keyboard is visible, I can edit.

Tried messing with focusing too, but that didn't work out too well. But that's just more my lack of understanding of focus than anything.

Aucun commentaire:

Enregistrer un commentaire