在PageViewer的Andr​​oid的BaseAdapter类中调用片段 [英] Calling Fragment from inside the BaseAdapter class in PageViewer Android

查看:195
本文介绍了在PageViewer的Andr​​oid的BaseAdapter类中调用片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是新来的Andr​​oid和我在我的项目中使用PageViewer显示选项卡刷卡和其他类似的东西。

我用4个标签和并用碎片为每个标签
现在我有哪个按钮是那里呼吁同一选项卡即另一片段列表的选项卡1,我需要更换相同选项卡上的片段。

我已经对所看到的链接栈的问题而说,使用广播听众在片段呼吁打击。我用它在我的片段类。

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

我得到我需要在框架布局调用错误

,因为它采用了Android的id,如果我将其更改为@ + ID,然后提示错误

 &LT;的FrameLayout
                    机器人:ID =@机器人:ID / tabcontent
                    机器人:layout_width =0dp
                    机器人:layout_height =0dp
                    机器人:layout_weight =0&GT;
                &LT; /&的FrameLayout GT;

我在我的片段用它来取代另一个的一个片段

 广播接收器mBroadcastReceiver =新的广播接收器(){
                @覆盖
                公共无效的onReceive(上下文的背景下,意图意图){
                    Toast.makeText(上下文中,Recived,
                               Toast.LENGTH_LONG).show();
                    FieldVisitFragment fieldvisitFragment =新FieldVisitFragment();
                    FragmentManager fragmentManager = getFragmentManager();
                    FragmentTransaction fragmentTransaction = fragmentManager
                            .beginTransaction();
                    fragmentTransaction.replace(需要知道什么ID通过,fieldvisitFragment);
                    fragmentTransaction.commit();
                }            };

我的显示卡的布局,如下图所示,我使用Fragement android.support.v4库。请帮助。

 &LT; TabHost
            机器人:ID =@机器人:ID / tabhost
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =900dp           机器人:layout_alignParentBottom =真            &GT;            &LT;的LinearLayout
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =FILL_PARENT
                机器人:方向=垂直&GT;                &LT;的FrameLayout
                    机器人:ID =@机器人:ID / tabcontent
                    机器人:layout_width =0dp
                    机器人:layout_height =0dp
                    机器人:layout_weight =0&GT;
                &LT; /&的FrameLayout GT;                &LT; android.support.v4.view.ViewPager
                    机器人:ID =@ + ID / viewpager
                    机器人:layout_width =FILL_PARENT
                    机器人:layout_height =135​​dp
                    机器人:layout_weight =1&GT;
                &LT; /android.support.v4.view.ViewPager>                &LT; TabWidget
                    机器人:ID =@机器人:ID /标签
                    机器人:layout_width =match_parent
                    机器人:layout_height =WRAP_CONTENT
                    机器人:方向=横向&GT;
                &LT; / TabWidget&GT;
            &LT; / LinearLayout中&GT;
        &LT; / TabHost&GT;


解决方案

使用这样的:

  Fragment.replace(RES_ID,fragement更换);

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>

解决方案

Use this:

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

这篇关于在PageViewer的Andr​​oid的BaseAdapter类中调用片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆