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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 激光测距芯片VL53L0X的使用与代码

    激光测距芯片VL53L0X的使用与代码一、介绍1、原理采用940nm垂直腔面发射激光器(Vertical-CavitySurface-EmittingLaser,简称VCSEL)发射出激光,激光碰到障碍物后反射回来被VL53L0X接收到,测量激光在空气中的传播时间,进而得到距离。VCSEL相关知识2、参数超小体积:4.4×2.4×1.0mm最大测距:2m发射的激光对眼镜安全,且完全不可见。工作电压:2.6to3.5V通信方式:IIC,400KHz,设备地址0x52,最低位是读…

    2022年6月2日
  • 计算机组成原理 寻址方式_计算机组成原理寻址方式的判断

    计算机组成原理 寻址方式_计算机组成原理寻址方式的判断一、寻址方式是指确定本条指令的数据地址以及下一条将要执行的指令地址的方法,与硬件结构紧密相关,而且直接影响指令格式和指令功能。分为指令寻址和数据寻址两大类。二、指令寻址分为顺序寻址和跳跃寻址两种。顺序寻址可通过程序计数器PC加1,自动形成下一条指令的地址;跳跃寻址则通过转移类指令实现。数据寻址种类较多,在指令字中必须设一字段来指明属于哪一种寻址方式。指令的地址码字段通常都不代表操作数的真实地址,把它称为真实地址,记作A。操作数的真实地址成为有效地址,记作EA,它是由寻址方式和形式地址共同来确定的。由

    2022年10月24日
  • 功能强大的radcontrols for Asp.net

    功能强大的radcontrols for Asp.netradcontrols类似vs套装的控件,只不过功能比其更加强大,灵活,开发也更快捷。radcontrols官方网址:http://www.telerik.com/分windows和asp.n

    2022年7月4日
  • Android 相机方向传感,如何在Android设备中获取相机传感器尺寸?[通俗易懂]

    Android 相机方向传感,如何在Android设备中获取相机传感器尺寸?[通俗易懂]从API级别21开始是可能的.从文档(https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SENSOR_INFO_PHYSICAL_SIZE):publicstaticfinalKeySENSOR_INFO_PHYSICAL_SIZEThephysical…

    2022年5月4日
  • 基于chromium for android开发Android浏览器

    基于chromium for android开发Android浏览器在上一篇文章<>中谈到了Google已经完全开源了ChromiumforAndroid,这样我们就完全可以开发与ChromeforAndroid媲美的Android浏览器了。通常浏览器的一些新特性和新功能会先出现在ChromiumforAndroid上,稳定后才会出现在ChromeforAndroid上,如果我们基于Chromiu

    2022年5月15日
  • python打开pkl文件_python判断文件名是否包含某字段

    python打开pkl文件_python判断文件名是否包含某字段   importcPickleaspicklef=open(‘path’)data=pickle.load(f)print(data)#showfile  

    2022年9月9日

发表回复

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

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