1

[Using the support library]

When attempting to use an EditText inside of a Fragment that is in my ScreenSlidePagerAdapter in which multiple Fragments are visible at once.

The second Fragment in the list contains an EditText. On Android 4.1 & 4.2 it works fine. On Android 2.3.6 (don't know about other versions), tapping the EditText will bring up the on screen keyboard, but will not focus the EditText. If I drag within the ScreenSlidePagerAdapter in such a way that the Fragment becomes considered "current", then the EditText will behave correctly.

A fixed layout is not acceptable, as everything must be generated dynamically and the number of Fragments visible can vary based on different criteria.

Any ideas on how to get it to behave correctly and without hard-coding?

Steven Byle
  • 13,149
  • 4
  • 45
  • 57
JSandusky
  • 21
  • 2
  • I've tried the following: public void onFocusChange(View v, boolean hasFocus) { if (v == tv) { ((LobbyAct)ChatFragment.this.getActivity()).pager.setCurrentItem(1); InputMethodManager inputMgr = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } } Which mostly works. But fails whenever another event such as a button press occurs. – JSandusky Apr 06 '13 at 04:06

1 Answers1

0

The

if (v == tv)

Of my prior comment needs to be concerned with focus

if (v == tv && hasFocus)

Full code:

if (v == tv && hasFocus) {
    ((LobbyAct)ChatFragment.this.getActivity()).pager.setCurrentItem(1);
    InputMethodManager inputMgr = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMgr.toggleSoftInput(0, 0);
}
JSandusky
  • 21
  • 2