Skip to content
Permalink
63525a17dd
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
30 lines (25 sloc) 1.1 KB
package com.example.jianhuayang.myfragments;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import layout.BlankFragment;
import layout.BlankFragment2;
public class DynamicActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
BlankFragment frag1 = new BlankFragment();
fragmentTransaction.replace(R.id.activity_dynamic, frag1);
} else {
BlankFragment2 frag2 = new BlankFragment2();
fragmentTransaction.replace(R.id.activity_dynamic, frag2);
}
fragmentTransaction.commit();
setContentView(R.layout.activity_dynamic);
}
}