11

I have FrameLayout container in which I want to add dynamically EditText. I need to set two imeOptions: IME_ACTION_DONE and IME_FLAG_NO_EXTRACT_UI in this same time but I have problem how to do it programmatically. My solution override my imeOptions (I now that is good behavior :) but I try everything)

And my secound question: How to set focus after create EditText programmatically? This method editText.requestFocus(); dosen't work for me. I want to open keyboard after postCardContainer.addView(editText);

  postCardContainer.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.topMargin = (int) event.getY()-50;
            params.leftMargin = (int) event.getX()-50;

            EditText editText = new EditText(NewPostcardActivity.this);
            editText.setSingleLine();
            editText.setBackgroundResource(R.color.transparent);
            editText.requestFocus();
            editText.setLayoutParams(params);
            editText.setCursorVisible(true);
            editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
            editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

            postCardContainer.addView(editText);

            return false;
        }
    });

Thanks

kazhiu
  • 749
  • 9
  • 21
  • Possible duplicate -http://stackoverflow.com/questions/17501426/android-imeoptions-change-programmatic – shweta_jain Apr 26 '14 at 05:19
  • No, I want to set IME_ACTION_DONE and IME_FLAG_NO_EXTRACT_UI on one EditText object not diffrent. Two attrs on one object. – kazhiu Apr 27 '14 at 18:51
  • Possible duplicate of http://stackoverflow.com/questions/3459168/imeoptions-actionnext-programmatically-how-to-jump-to-next-field – Daniele D. Sep 13 '16 at 14:56
  • Possible duplicate of http://stackoverflow.com/questions/2004344/how-do-i-handle-imeoptions-done-button-click – Daniele D. Sep 13 '16 at 14:58

1 Answers1

15

Try like as below.

editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
lelloman
  • 13,883
  • 5
  • 63
  • 85
Karthikeyan
  • 452
  • 4
  • 13