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


相关推荐

  • 数据库期末考试复习题 第二�

    数据库期末考试复习题 第二�

    2021年11月14日
    40
  • 盘点分布式文件存储系统

    盘点分布式文件存储系统在项目的数据存储中,结构化数据通常采用关系型数据库,非结构化数据(文件)的存储就有很多种方式,服务器本地存储、Nas挂载、ftp等等,今天就来盘点一下,分布式文件存储系统。

    2022年6月10日
    90
  • vue可以生成静态页面吗(vue视频为什么不能全屏)

    新建项目vue默认为body设置了margin:8px我们可以在App.vue<style>中,设置width和height为100%,对margin进行重写去掉边距html,body{width:100%;height:100%;margin:0;}

    2022年4月14日
    45
  • 【Cubieboard2】配置编译内核支持SPI全双工通信驱动

    【Cubieboard2】配置编译内核支持SPI全双工通信驱动1,cubieboard2A20系列,无论是官方还是社区的系统,默认都是不支持SPI总线驱动的。需要重新编译配置内核,修改文件才能支持SPI全双工通信。本文以Cuieboard2Debain为例,进行讲解;2,重新编译配置内核(1)先去官网下载对应版本的linux内核源码,地址:https://github.com/linux-sunxi/linux-sunxi我下载的是sun-xi

    2022年7月22日
    11
  • 无序链表排序_双向链表排序算法

    无序链表排序_双向链表排序算法需求给定一个无序的链表,输出有序的链表。分析链表排序比较特殊,由于不连续的性质,所以在进行排序的时候要引入外排思想,因此归并排序或者多路归并就成为了排序的选择。归并排序分为拆分、合并两个阶段:1.拆分需要拆分出链表中间节点,并赋值NULL阶段,形成两个独立的链表,直到拆分成单个节点为止。2.合并由于此时没个链表都为单节点,所以实质上是个有序链表合并问题。代码下面

    2022年10月11日
    3
  • touchstart与click同时触发

    touchstart与click同时触发产生冲突的原因我们可以给某个元素同时绑定touchstart和click事件,但这将会导致本篇文章解决的问题–这两个事件在移动设备上会发生冲突。由于移动设备能够同时识别touchstart和click事件,因此当用户点击目标元素时,绑定在目标元素上的touchstart事件与click事件(约300ms后)会依次被触发,也就是说,我们所绑定的回调函数会被执行两次!。…

    2022年6月19日
    120

发表回复

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

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