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


相关推荐

  • BInder机制总结

    BInder机制总结BInder机制Linux内核的基础知识+进程隔离/虚拟地址空间操作系统当中为了保证进程间互不干扰,设计了进程隔离的技术,避免了一个进程去操作另一个进程的数据。进程隔离用到了虚拟地址空间,不

    2022年7月3日
    26
  • jsp开发环境搭建实验报告_eclipse安卓开发环境搭建

    jsp开发环境搭建实验报告_eclipse安卓开发环境搭建一.配置Java开发工具(JDK)1.下载JDKhttp://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html使用默认安装路径,默认安装在C盘中。如果更改安装路径,在安装jre时,更改安装路径,会出现选择文件夹不为空的情况。所以最好的办法是安装在默认路径下。2.环

    2022年10月20日
    3
  • ubuntu安装vscode的两种方法_vscode vim

    ubuntu安装vscode的两种方法_vscode vimUbuntu16.04安装VisualStudioCode出现问题的解决一、前述关于ubuntu安装VisualStudioCode这里不在说明。这里记录两点自己安装过程中遇到的问题。二、umake安装出现问题解决usage:umakeweb[-h]{firefox-dev,phantomjs}…umakeweb:error:argumentframew…

    2026年1月17日
    5
  • 用斐波那契数列来说明递归和迭代的区别「建议收藏」

    用斐波那契数列来说明递归和迭代的区别「建议收藏」递归:自己调用自己迭代:反复替换的意思递归与迭代都是基于控制结构:迭代用重复结构,而递归用选择结构。递归与迭代都涉及重复:迭代显式使用重复结构,而递归通过重复函数调用实现重复。递归与迭代都涉及终止测试:迭代在循环条件失败时终止,递归在遇到基本情况时终止。使用计数器控制重复的迭代和递归都逐渐到达终止点:迭代一直修改计数器,直到计数器值使循环条件失败;递归不断产生最初问题的简化副本

    2022年6月3日
    44
  • 【备忘录】麦克斯韦速率分布

    【备忘录】麦克斯韦速率分布突然想做麦克斯韦速度分布的复习,找到了以前读《新概念物理学·热学》的笔记发现高中时我如何臆测不得其解的东西竟然被这一页提纲挈领的笔记就解释很清楚了如果让我给高中时的我带话帮助他迅速理解这

    2022年7月4日
    25
  • manjaro 安装分区以及配置方案

    manjaro 安装分区以及配置方案制作启动盘windows下制作启动盘推荐在windows下使用Rufus工具来制作启动盘,做成启动盘后还能用来存储文件linux下制作启动盘使用dd命令,使用该命令做成启动盘后U盘就不能用来存储文件了,具体命令格式可以看wikihttps://wiki.manjaro.org/index.php?title=Burn_an_ISO_File#Using_t…

    2022年6月7日
    71

发表回复

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

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