Reputation: 1157
i need some help in addition to android-layouts. For eyample:
Actually I use a view called daily.xml.These view contains a flipper, which is filled programmatically with 5 ListViews to flip around if the user want to.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background">
<de.oszimtcc.timetableview.TimetableFlipperView
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_margin="20dp"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent" >
</de.oszimtcc.timetableview.TimetableFlipperView>
</LinearLayout>
Flipper in TimetableScreen.java
activity.setContentView(R.layout.daily);
Log.i(TimetableApplication.LOG_TAG,"Start create Timetable-Aplication");
activity.setContentView(R.layout.daily);
activity.inflater = LayoutInflater.from(this.activity);
flipper = (TimetableFlipperView) activity.findViewById(R.id.flipper);
dayListView = (ListView) activity.findViewById(R.id.dayListView);
flipper.AddContent(**Content to show **);
Now, I want to add a landscapemode.In these mode i won't hava such flipper, cause there is enough space to show all ListViews on a horizontal linear layout.So i created a layout-land Resource-Folder an add another daily.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/background">
<de.oszimtcc.timetableview.BlockListView
android:id="@+id/dayListViewMonday"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="5dp"
android:listSelector="@drawable/day_selector"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent">
</de.oszimtcc.timetableview.BlockListView>
...the same ListView again for 4 times, with different android:id...
</LinearLayout>
But how can i handle this into my TimetableScreen.java Class?Because there is no flipper i can't use my default-constructor to init the class.Should I call different methods every time the onCreate is called or is there any nicer possibility to handle it?
Thanks a lot Kooki!
Upvotes: 4
Views: 248
Reputation: 5850
You could use getResources().getConfiguration().orientation
, in order to find out the screen orientation. If its a landscape mode, dont initialize the flipper variable.
I just added one line in your code, check the if control statement.
activity.setContentView(R.layout.daily);
Log.i(TimetableApplication.LOG_TAG,"Start create Timetable-Aplication");
activity.setContentView(R.layout.daily);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_POTRAIT) { //Check this statement
activity.inflater = LayoutInflater.from(this.activity);
flipper = (TimetableFlipperView) activity.findViewById(R.id.flipper);
dayListView = (ListView) activity.findViewById(R.id.dayListView);
flipper.AddContent(**Content to show **);
} else {
//Code for Landscape mode
}
Upvotes: 3