Activity跳转fragment

Activity跳转fragmentfragment不能单独存在,必须依附在Activity上,所以在Activity跳转时,实际是跳到fragment的宿主上代码:Activity点击跳转里Intentintent=newIntent(ListDetailsActivity.this,MainActivity.class);intent.putExtra("id",2);startActivity(intent);frag…

大家好,又见面了,我是你们的朋友全栈君。

fragment不能单独存在,必须依附在Activity上,所以在Activity跳转时,实际是跳到fragment的宿主上

代码:

Activity点击跳转里

Intent intent=new Intent(ListDetailsActivity.this,MainActivity.class);
intent.putExtra("id",2);
startActivity(intent);

fragment宿主Activity

int id = getIntent().getIntExtra("id", 0);//获取intent值
if (id == 2) {
  
  //判断intent值
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.container,new MyFragent())//设置显示fragment
            .addToBackStack(null)
            .commit();
    mRadioButton2.setChecked(true);//给按钮设置状态
}

布局最好用

<FrameLayout  android:id="@+id/container"  android:layout_width="match_parent"  android:layout_height="0dip"  android:layout_weight="1.0" >
</FrameLayout>

<RadioGroup  android:id="@+id/main_radio"  android:layout_width="fill_parent"  android:layout_height="wrap_content"  android:layout_gravity="bottom"  android:layout_marginBottom="-6dp"  android:gravity="bottom"  android:orientation="horizontal" >

    <RadioButton  android:id="@+id/radio_button0"  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_weight="1"  android:background="@drawable/tab_homepage"  android:button="@null"  android:layout_gravity="center_vertical"  android:gravity="center_horizontal"  />

    <RadioButton  android:id="@+id/radio_button1"  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_weight="1"  android:button="@null"  android:background="@drawable/tab_class"  android:layout_gravity="center_vertical"  android:gravity="center_horizontal"  />

    <RadioButton  android:id="@+id/radio_button2"  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_weight="1"  android:button="@null"  android:background="@drawable/tab_shopcar"  android:layout_gravity="center_vertical"  android:gravity="center_horizontal"  />

    <RadioButton  android:id="@+id/radio_button3"  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_weight="1"  android:button="@null"  android:background="@drawable/tab_find"  android:layout_gravity="center_vertical"  android:gravity="center_horizontal"  />

    <RadioButton  android:id="@+id/radio_button4"  android:layout_width="0dp"  android:layout_height="wrap_content"  android:layout_weight="1"  android:button="@null"  android:background="@drawable/tab_mine"  android:layout_gravity="center_vertical"  android:gravity="center_horizontal"  />
</RadioGroup>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/143418.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • tensorflow中常用激活函数和损失函数

    激活函数各激活函数曲线对比常用激活函数:tf.sigmoid()tf.tanh()tf.nn.relu()tf.nn.softplus()tf.nn.softmax()tf.nn.dr

    2021年12月30日
    45
  • No way to disable datapump estimate?

    No way to disable datapump estimate?

    2021年8月8日
    69
  • ubuntu设置中文输入法_ubuntu如何使用中文输入法

    ubuntu设置中文输入法_ubuntu如何使用中文输入法找到设置 选择区域和语言点击ManageInstalledLanguagees,提示安装的话安装即可4.点击图示内容。5.将Chinese(simplified)勾选上右键点击住,将汉语拖到第一位重启Ubuntu6.在输入源中点击+号,选中里面的汉语,再选中里面的汉语(IntelligentPinyin),添加即可,并将其移动到第一位。在输入源中点击+号,…

    2022年9月26日
    0
  • SVN服务器部署「建议收藏」

    SVN服务器部署「建议收藏」1,关闭防火墙或者开放对应端口3690,2,Yum下载安装subversion检查SVN是否安装成功svnserve–version3,建立SVN版本库3.1因为大磁盘挂载在/home下,所以我是在/home下创建的版本库,mkdir/home/svn创建一个文件夹(所有项目库都在此目录下创建)3.2创建svn版本库svnadmincreate/home/svn/liangz_artliangz_art才是项目版本库的名字,后面开发人员checkout时就要用这个名称,项

    2022年7月19日
    17
  • AngularJS简介

    AngularJS简介AngularJS简介AngularJS是一个JavaScript矿建,他是一个JavaSscript编写的库。可以通过&lt;script&gt;标签添加到HTML页面。AngularJS是通过指令扩展了HTML,且通过表达式绑定数据到HTML。地址:&lt;scriptsrc="http://apps.bdimg.com/libs/angular.js/1.4.6/angul…

    2022年7月25日
    5
  • 关于使用preparestatement来实现模糊查询

    关于使用preparestatement来实现模糊查询关于使用prparestatement来实现模糊查询

    2022年6月4日
    35

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号