类型 FragmentTransaction 中的方法 replace(int, Fragment)对于参数(int, Fragment1)不适用

来源:互联网 发布:企业网络监控软件 编辑:程序博客网 时间:2024/04/26 10:54
package com.example.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Display;


public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Display display = getWindowManager().getDefaultDisplay();
if(display.getWidth()>display.getHeight()){
Fragment1 fragment1 = new Fragment1();
//FragmentTransaction
//获取fragment,开启一个事物,加入fragment,提交事物
getFragmentManager().beginTransaction().replace(R.id.main_layout,fragment1).commit();
Log.e("Fragment","fragment1");
}else{
Fragment2 fragment2 = new Fragment2();
getFragmentManager().beginTransaction().replace(R.id.main_layout,fragment2).commit();
Log.e("Fragment","fragment2");
}
}
}


类型 FragmentTransaction 中的方法 replace(int, Fragment)对于参数(int, Fragment1)不适用


0 0
原创粉丝点击