View Single Post
  #1 (permalink)  
Old July 6th, 2015, 02:23 PM
zeorox zeorox is offline
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation chapter 2 -getting error in fragmenttransaction.replace method

public void onCreate(Bundle savedInstanceState) {

FragmentTransaction fragmentTransaction =

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( metrics);

if (metrics.widthPixels > metrics.heightPixels)
//---landscape mode---
Fragment1 fragment1 = new Fragment1() ;
// refers to the content
// view of the activity
fragmentTransaction.replace(, fragment1);
}else {
//---portrait mode---
Fragment2 fragment2 = new Fragment2();
fragmentTransaction.replace(, fragment2);
//---add to the back stack---

getting error in the replace method
-The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, Fragment1)

i replaced display class getWidth(),and getHeight() with DisplayMetrics class due to dreprication (hoping after the solution for the replace it will work,havnt checked it somewhere else)

helpp fast

Last edited by zeorox; July 8th, 2015 at 02:44 AM.. Reason: dynamically adding the fragment
Reply With Quote