0

I have searched a lot for a solution but nothing works.

Update: post at bottom

I have a ScrollView and a FrameLayout as child. Then I set up some EditText programmatically with LayoutParams.

Furthermore, I activated the ime options, so it will go to the next Edittext automatically. When it now goes to the next one, the layout doesn't scroll up and the keyboard hides the EditText.

Answers like android:windowSoftInputMode="adjustPan / adjustResize" didn't work. I also tried to scroll manually with

Spieler1.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                int current_pos = scroll2.getScrollY();
                scroll2.smoothScrollTo(0,(int)(current_pos + height/4));
                scroll2.post(new Runnable() {
                    @Override
                    public void run() {
                        Spieler2.requestFocus();
                        InputMethodManager imm = (InputMethodManager)   getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                    }
                });

                return true;
            }
            return false;
        }
    }); 

Strange things happened: It wanted to scroll up, but then suddenly goes back to the original position covering the EditText.

I have no idea, why it doesn't scsroll up, but maybe you have.

Thanks for answering.

Marc
  • 1
  • 5

1 Answers1

0

I suspect the smoothScrollTo() call causes the behavior you've seen. You might want to use the android:nextFocusDown attribute for your first EditText instead of setting the OnKeyListener.

Crispert
  • 1,102
  • 7
  • 13
  • I tested all combinations, also without the smoothScrollTo(). Since I am using code and not the xml, android: is useless for me. Is there an alternative for code? – Marc Sep 17 '17 at 10:22
  • You can set the next focusable view in Java as well: Spieler1.setNextFocusDownId(Spieler2.getId()); Just ensure that the id of Spieler2 has been generated before this call (you can set it yourself if needed). – Crispert Sep 17 '17 at 10:24
  • No change. Going to next edittext via ime options but no scrolling (with nextfocusdown) – Marc Sep 17 '17 at 11:15
  • Do you change the scroll position of scroll2 or toggle the keyboard anywhere else in the Activity? – Crispert Sep 17 '17 at 11:17
  • I request focus for first edittext. Then I open the keyboard (because not appearing by itself with getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); scroll2 was only for the manual scrolling, not used anywhere else. – Marc Sep 17 '17 at 11:23
  • After looking at https://stackoverflow.com/questions/5105354/how-to-show-soft-keyboard-when-edittext-is-focused i think the imm.toggleSoftInput(InputMethodManager.SHOW_FORCED) or setSoftInputMode(WindowManager.LayoutParams.SOFT‌​_INPUT_STATE_VISIBLE‌​) is preventing the content from scrolling because they keyboard remains on screen until it will be closed explicitly. You might want to try other modes mentioned on that page such as SHOW_IMPLICIT. – Crispert Sep 17 '17 at 11:37