Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 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 Reply

0 votes
by (71.8m points)

Use this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...