2

Simply put:

A ViewPager in a FragmentActivity, with 4 Fragments

A TextView in the layout above the ViewPager outside of the Fragments

I "add" a Fragment in place of the layout of another Fragment:

getSupportFragmentManager()
    .beginTransaction()
    .add(R.layout.activity, fragmentToPush)
    .addToBackStack("1")
    .commit();

I clean the backstack :

getSupportFragmentManager()
    .popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

After that, the keyboard does not show anymore on press. The Textview has the focus, but the keyboard does not go o

EDIT :

The TextView is already not focusable after the the "add". I'm using a AutoCompleteTextView

what i'm doing with it :

    mSearchAutoCompletion = (AutoCompleteTextView)
        mIncludeSearchLayout.findViewById(R.id.search_text);

        mSearchAutoCompletion.addTextChangedListener(new 
        TextWatcher() {... // nothing more with the textview

        mSearchAutoCompletion.setOnEditorActionListener(new
        OnEditorActionListener() {... // nothing more with the textview

EDIT2 : The Layout (i'm using an include):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_home_layout_search"
    android:layout_width="match_parent"
    android:layout_height="@dimen/edit_text"
    android:background="@drawable/gradient_banner_inverse" >

    <ImageButton
        android:id="@+id/search_button"
        android:layout_width="@dimen/edit_text"
        android:layout_height="@dimen/edit_text"
        android:layout_alignParentLeft="true"
        android:adjustViewBounds="true"
        android:background="@drawable/selector_blue"
        android:padding="2dp"
        android:scaleType="centerInside"
        android:src="@drawable/search" />

    <AutoCompleteTextView
        android:id="@+id/search_text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="1px"
        android:layout_marginRight="1px"
        android:layout_marginTop="1px"
        android:layout_toRightOf="@+id/search_button"
        android:background="@android:color/white"
        android:focusableInTouchMode="true"
        android:hint="@string/search_hint"
        android:imeOptions="actionSearch"
        android:inputType="text"
        android:paddingLeft="@dimen/margin_medium"
        android:paddingRight="@dimen/margin_medium"
        android:singleLine="true"
        android:textColor="@color/clr_dark_grey" />

    <ImageButton
        android:id="@+id/search_cross"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="1px"
        android:layout_marginRight="1px"
        android:layout_marginTop="1px"
        android:background="@android:color/white"
        android:src="@android:drawable/ic_menu_close_clear_cancel"
        android:visibility="gone" />

</RelativeLayout>

Then the include :

<include
    android:id="@+id/activity_search"
    android:layout_width="wrap_content"
    android:layout_height="@dimen/edit_text"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="@dimen/margin_large"
    android:layout_marginRight="@dimen/margin_large"
    android:layout_marginTop="@dimen/margin_large"
    layout="@layout/view_search" />

EDIT3 : I tried to show the keyboard mannually

mSearchAutoCompletion.setOnClickListener(this);

case R.id.search_text:
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.toggleSoftInputFromWindow(mSearchAutoCompletion.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
                break;
  • At first i select the textfield, it show and then hide the keyboard really fast (strange)
  • When i add a fragment, the keyboard is ok
  • When i remove the fragment the keyboard does not respond anymore
  • i add the fragment again the keyboard is ok again
14
  • are you using all the references of textview inside oncreateView? Jun 24, 2014 at 15:44
  • The textview is fully fonctionnal, i get the view in onCreateview and i set the listeners in onViewCreated
    – An-droid
    Jun 24, 2014 at 15:48
  • what I usually do is make textview class level variable initialize it in oncreateview use it in onStart. and i only use popBackStackImmediate() this approach has always worked for me and it cleans the backstack. Try .popBackStackImmediate("1", FragmentManager.POP_BACK_STACK_INCLUSIVE). Jun 24, 2014 at 15:56
  • I editted the question, i lose focus after the "add"/"replace" and i use AutoCompleteTextView
    – An-droid
    Jun 24, 2014 at 15:59
  • please add some more code. the code where the textview is used. I guess that the textview is not defined in the activity or fragment containing your viewpager but inside one of the fragment Jun 24, 2014 at 16:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.