Hy all,

i have a problem with the Fragments, and i really dont know how to solve it. 
hopefully somebody can help me.

I have a layout for portrait mode: 
   
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android";

android:layout_width="match_parent" android:layout_height="match_parent">

<fragment class="ch.kusar.dwr.layout.OverviewFragment"

 android:id="@+id/overview" android:layout_width="match_parent" 
android:layout_gravity="bottom" android:layout_height="match_parent"/>

</RelativeLayout>


and a layout for landscape mode:
   
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android";

android:orientation="horizontal" android:layout_width="match_parent"

android:layout_height="match_parent">

<fragment class="ch.kusar.dwr.layout.OverviewFragment"

 android:id="@+id/overview" android:layout_width="fill_parent"

 android:layout_height="60dp" />

<fragment class="ch.kusar.dwr.layout.ContentFragment"

 android:id="@+id/content" android:layout_width="fill_parent"

 android:layout_height="fill_parent" android:layout_below="@+id/overview" />

</RelativeLayout>



In the OverviewFragment, i have a method to show details.

   void showDetails(int index) {

 currentButton = index;


 if (mDualPane) {

 // We can display everything in-place with fragments, so update

 // the list to highlight the selected item and show the data.

 // getListView().setItemChecked(index, true);


  // Check what fragment is currently shown, replace if needed.

 ContentFragment cf = (ContentFragment) getFragmentManager()

  .findFragmentById(R.id.content); // /hereChanged

 // if (cf == null || (cf.getPressedButton() != index)) {

 if (cf == null

  || (prefs.getInt(ContentEnum.PRESSEDBUTTON.name(), 0) != index)) {

  // Make new fragment to show this selection.

  // cf = ContentFragment.newInstance(index);

  setPressedButton(index);

  // Execute a transaction, replacing any existing fragment

  // with this one inside the frame.

  FragmentTransaction ft = getFragmentManager()

   .beginTransaction();

  ft.replace(R.id.content, cf); // /hereChanged

  ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

  ft.commit();

 }

 } else {

 // Otherwise we need to launch a new activity to display

 // the dialog fragment with selected text.

 Intent intent = new Intent();

 intent.setClass(getActivity(), ContentActivity.class);

 // intent.putExtra("button", index);

 setPressedButton(index);

 startActivity(intent);

 }

}


and the ContentFragment onCreateView looks like this:

   @Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

 Bundle savedInstanceState) {

 Log.e("ContentFragment.onCreateView", "onCreateView");

 // TODO Auto-generated method stub

 if (container == null) {

 // // We have different layouts, and in one of them this

 // // fragment's containing frame doesn't exist. The fragment

 // // may still be created from its saved state, but there is

 // // no reason to try to create its view hierarchy because it

 // // won't be displayed. Note this is not needed -- we could

 // // just run the code below, where we would create and return

 // // the view hierarchy; it would just never be used.

 //return null;

 }

  if (prefs.getInt(ContentEnum.PRESSEDBUTTON.name(), 0) == ContentEnum.
REMOTE

  .ordinal()) {

 view = ContentRemote.getRemoteView(inflater, container,

  savedInstanceState);

 Preferences.setPreferences(getActivity());

 }

...

}


the if container == null, is always true. Why is this so?


and the other problem is, when i press a button, the showDetails is called. 
When im in portrait mode, it works fine.

But when im in landscape mode, the following error is shown when i press a 
button. 


Does anyone has an idea how can i solve this?


thank you for your support




<https://lh5.googleusercontent.com/_7FGGBnFM_RE/TcvqTciA4jI/AAAAAAAAAB4/VC7DswkWj6g/screen-capture-2.png>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to