Any issue I've found related to this has always been resolved by correcting the layout files paths, and I'm pretty sure mine are correct.
I have a very simple layout made that is supposed to have a split view for large landscape devices. So I have:
- layout/main.xml
- layout/main_twopane.xml
- values/main.xml
- values-large-land/main.xml
And I am loading a Nexus 7 Tablet in landscape (which is classified as a large device). The problem is it is always loading main.xml
when according to the Android documentation what I have should load the two pane layout for large devices on landscape.
Here is the code:
layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_catches"
android:name="com.cohenadair.anglerslog.fragments.CatchesFragment"
tools:layout="@layout/fragment_catches"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
layout/main_twopane.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_catches"
android:name="com.cohenadair.anglerslog.fragments.CatchesFragment"
tools:layout="@layout/fragment_catches"
android:layout_width="200dp"
android:layout_height="match_parent" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_catch"
android:name="com.cohenadair.anglerslog.fragments.CatchFragment"
tools:layout="@layout/fragment_catch"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</LinearLayout>
values/main.xml
<resources>
<item name="main_layout" type="layout">@layout/main</item>
<bool name="has_two_panes">false</bool>
</resources>
values-large-land/main.xml
<resources>
<item name="main_layout" type="layout">@layout/main_twopane</item>
<bool name="has_two_panes">true</bool>
</resources>
The code that loads the layout, in MainActivity.java
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
And in each individual fragment:
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View aView = super.onCreateView(inflater, container, savedInstanceState);
// set the list's adapter
ArrayAdapter adapter = new ArrayAdapter<Catch>(this.getActivity(), android.R.layout.simple_list_item_1, Logbook.getSharedLogbook().getCatches());
setListAdapter(adapter);
return aView;
}
And
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_catch, container, false);
}