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


相关推荐

  • 带你从零开始,快速学会 Matlab GUI

    带你从零开始,快速学会 Matlab GUI本文来自作者 木木小迷哥 在 GitChat 上分享「MatlabGUI零基础学员快速入门」,「阅读原文」查看交流实录「文末高能」编辑|洛肯Matlab广泛地应用于数学分析、计算、自动控制、系统仿真、数字信号处理、图像处理、数理统计、人工智能、通信工程和金融系统等领域。本活动针对零基础学员,结合个人经验,使Matlab新手少走弯路、快速入门(相应的代码用斜体

    2022年4月30日
    66
  • linux netstat -an命令,linux 命令之netstat[通俗易懂]

    linux netstat -an命令,linux 命令之netstat[通俗易懂]在linux中netstat命令的作用是查看TCP/IP网络当前所开放端口,所对应的本地和外地端口信息。netstat命令的格式netstat[-a][-e][-n][-o][-pProtocol][-r][-s][Interval]各参数选项的含义a显示所有socket,包括正在监听的。-c每隔1秒就重新显示一遍,直到用户中断它。-i显示所有网络接口的信息,格式“netstat-i”…

    2022年8月30日
    3
  • 将ipynb转化为pdf_jupyter打开ipynb文件

    将ipynb转化为pdf_jupyter打开ipynb文件将ipynb文件转换为markdownjupyternotebook文件(扩展:ipynb)转换说明转换jupyternotebook文件(扩展:ipynb)使用jupyternotebook转为为markdown文档文件。转换说明执行命名进行转化;文件名有空格推荐:“LinerR.ipynb”方式;LinerR.ipynb种诺是有图片,会自动保存至当前LinerR_f…

    2022年8月29日
    3
  • 左连接,右连接,内连接,全连接的区别及使用方式_外连接与内连接的区别

    左连接,右连接,内连接,全连接的区别及使用方式_外连接与内连接的区别左连接,右连接,内连接,全连接的区别及使用众所周知,我们在写sql时经常会用到多表查询数据,这就是涉及到连接的问题包括,左连接,右连接,内连接,全外连接。定义:左连接(leftjoin):返回包括左表的所有记录和右表中连接字段相等的记录右连接(rightjoin):返回包括右表的所有记录和左表中连接字段相等的记录等值连接或者叫内连接(innerjoin):只返回两表相连相等的行全外连接(fulljoin):返回左右表中所有的记录和左右表中连接字段相等的记录。只说概念还不够清晰举个例子

    2022年9月16日
    5
  • C++中voliate关键字

    C++中voliate关键字voliate变量是随时变化的,用voliate修饰的运算,编译器不进行优化,以免出错。对于一个普通变量,为提高存取速率,编译器会先将变量的值存储在一个寄存器中,以后再取变量值时,就存寄存器中取出。但是用voliate修饰的变量,就说明这个变量会发生意向不到的改变。也就是说,优化器每次在读取该值时,不会假设这个值了,每次都会小心的在读取这个变量的值,而不是在寄存器中取保留的备份。那么,…

    2022年6月6日
    31
  • vue slot插槽_vue插槽的使用场景

    vue slot插槽_vue插槽的使用场景为什么使用slotslot(插槽)在生活中很多地方都有插槽,电脑usb的插槽,插板当中的电源插槽插槽的目的是为了让我们原来的设备具备更多的扩展性比如电脑的USB我们可以插入U盘,手机,鼠标,键

    2022年8月7日
    6

发表回复

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

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