activity跳转到fragment
2016-06-02 13:08
393 查看
问题:如何实现从一个activity跳转到MainActivity中的一个fragment,并且底部的RadioButton不变?
回答:通过使用自定义变量,如type,来进行传值判断。
例子:
[java] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
type = getIntent().getIntExtra("type", 0);
// 判断type是否为1
if (type == 1) {
// 声明GoodsInfoFragment对象
// GoodsInfoFragment goodsInfoFragment = new GoodsInfoFragment();
// 传值
// Bundle bundle = new Bundle();
// bundle.putInt("id", getIntent().getIntExtra("id", 0));
// System.out.println(getIntent().getIntExtra("id", 0)+"////////");
// goodsInfoFragment.setArguments(bundle);
// 跳转界面
transaction.add(R.id.main_content, new LoginFragment(), "login");
}
if (type == 2) {
// 声明TransmitWorkFragment对象
TransmitWorkFragment transmitWorkFragment = null;
if (position == 1) {
transmitWorkFragment = new TransmitWorkFragment(type);
} else {
transmitWorkFragment = new TransmitWorkFragment();
}
// 跳转界面
transaction.add(R.id.main_content, transmitWorkFragment,
"transmitwork");
[java] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
Intent intent=new Intent(HomeworkNoActivity.this,MainActivity.class);
intent.putExtra("type", 1);
startActivity(intent);
回答:通过使用自定义变量,如type,来进行传值判断。
例子:
[java] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
type = getIntent().getIntExtra("type", 0);
// 判断type是否为1
if (type == 1) {
// 声明GoodsInfoFragment对象
// GoodsInfoFragment goodsInfoFragment = new GoodsInfoFragment();
// 传值
// Bundle bundle = new Bundle();
// bundle.putInt("id", getIntent().getIntExtra("id", 0));
// System.out.println(getIntent().getIntExtra("id", 0)+"////////");
// goodsInfoFragment.setArguments(bundle);
// 跳转界面
transaction.add(R.id.main_content, new LoginFragment(), "login");
}
if (type == 2) {
// 声明TransmitWorkFragment对象
TransmitWorkFragment transmitWorkFragment = null;
if (position == 1) {
transmitWorkFragment = new TransmitWorkFragment(type);
} else {
transmitWorkFragment = new TransmitWorkFragment();
}
// 跳转界面
transaction.add(R.id.main_content, transmitWorkFragment,
"transmitwork");
[java] view
plain copy
![](https://code.csdn.net/assets/CODE_ico.png)
Intent intent=new Intent(HomeworkNoActivity.this,MainActivity.class);
intent.putExtra("type", 1);
startActivity(intent);
相关文章推荐
- PHP 计算两个时间相差的天
- php 获取当天或某个日期是星期几
- php 格式化时间(2014-11-29)
- 表格隔行换色效果
- 剑指Offer面试题1
- Qt MySQL驱动安装
- php中asp mod相似的做法&nbsp…
- php 字符串的连接
- PHP返回指定月份的天数
- php计算两个日期相差多少天(日)…
- PHP确定当月天数
- PHP 循环输出今天及以后九天的时间
- PHP 获取本月/本周第一天/最…
- ASCII码对应表chr(9)、chr(10)、ch…
- ps cs6 画边效果边框教程
- ps cs6 画笔描边
- Photoshop制作印章效果
- 图片转换效果
- Windows Server 2003架…
- Window 2003 Server&nbs…