0

I have tab bar with ViewPager and some List, that i can click and get my ViewPager behind fragmant. I have some issues with changing my android.support.v4.view.ViewPager with fragment by using replace. here is my layout in wich i contain them:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="6">
            <fragment
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/orders_fragment"
                android:name="fragments.OrderFragment1"
                tools:layout="@layout/fragment_2" />


            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/primaryColor"/>



        </RelativeLayout>

I'm trying to do it this way:

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            FragmentManager manager = getSupportFragmentManager();
            FragmentTransaction transaction=manager.beginTransaction();
            Fragment f1 = manager.findFragmentById(R.id.pager);
            transaction.remove(f1);
            transaction.commit();
        }
    });

Were i am wrong? can i do this in my way? or there is some special way to do this kind of things? Im new in this so if some1 have an example or something it wood be grate.

1 Answers1

0

ViewPager should be the fisrt element of the layout. Now it's probably the fragment is not clickable and focusable. Try this:

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="6">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/primaryColor"/>

             <fragment
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/orders_fragment"
                android:name="fragments.OrderFragment1"
                tools:layout="@layout/fragment_2" />


        </RelativeLayout>

Also, you have here an example of viewPager

Community
  • 1
  • 1
juliocb92
  • 96
  • 2
  • 12
  • if there will be fragment after ViewPage it would we seen on top of it, i whant that it will be seen only after click on List – Zoltan Kurtyak May 30 '15 at 12:10