Permalink
Cannot retrieve contributors at this time
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?
TEACHING-MATERIALS/Week_05_AdapterViews_and_Fragments/MyFragments/app/src/main/java/com/example/jianhuayang/myfragments/DynamicActivity.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
30 lines (25 sloc)
1.1 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |