问题:如何实现从一个activity跳转到MainActivity中的一个fragment,并且底部的RadioButton不变?
回答:通过使用自定义变量,如type,来进行传值判断。
例子:
- 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");
- Intent intent=new Intent(HomeworkNoActivity.this,MainActivity.class);
- intent.putExtra("type", 1);
- startActivity(intent);