Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

Calling Fragment from inside the BaseAdapter class in PageViewer Android

Hi I am new to Android and am using PageViewer in my project to show Tab swiping and other such stuff

I have used 4 tabs and and used fragments for each tab Now 1 of the tabs I have a list on which button is there to call another fragment on same Tab i.e. I need to replace the fragment on the same tab .

I have hit upon this stack question as seen in link which says to use Broadcast listener to call upon fragment . I used it in my Fragment class .

http://stackoverflow.com/questions/22265378/how-to-call-a-fragment-from-baseadapter-class-android/22265433#22265433

I get an error where I need to call upon the frame layout

as it uses android id if I change it to @+id then it gives error

   <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_weight="0" >
                </FrameLayout>

I am using this in my Fragment to replace the one Fragment by another

BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    Toast.makeText(context, "Recived", 
                               Toast.LENGTH_LONG).show();
                    FieldVisitFragment fieldvisitFragment = new FieldVisitFragment();
                    FragmentManager fragmentManager = getFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager
                            .beginTransaction();
                    fragmentTransaction.replace(need to know what id to pass, fieldvisitFragment);
                    fragmentTransaction.commit();
                }



            };

My layout for displaying tab is as seen below and I am using android.support.v4 libraries for Fragement . Kindly help .

<TabHost
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="900dp" 

           android:layout_alignParentBottom="true"

            >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_weight="0" >
                </FrameLayout>

                <android.support.v4.view.ViewPager
                    android:id="@+id/viewpager"
                    android:layout_width="fill_parent"
                    android:layout_height="135dp"
                    android:layout_weight="1" >
                </android.support.v4.view.ViewPager>

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"


                    android:orientation="horizontal" >
                </TabWidget>
            </LinearLayout>
        </TabHost>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this:

Fragment.replace("res_id",fragement to replace);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...