I've just taken a look at the Master/Detail Flow template and I can't figure 2 things out.
1) Why does it require Android version 11 when the code it generates seems to use the Fragment compatibility support? In particular, why can't you generate templates that run off Android version 8? (e.g. this import)
import android.support.v4.app.FragmentActivity;
2) How does the main Activity know whether to show the details in a new Activity or in the details pane if it's big enough? It seems to do it via this code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_list);
if (findViewById(R.id.item_detail_container) != null) {
mTwoPane = true;
((ItemListFragment) getSupportFragmentManager()
.findFragmentById(R.id.item_list))
.setActivateOnItemClick(true);
}
}
setContentView(R.layout.activity_item_list);
sets the layout to a ListFragment
which just sets its own adapter but I can't see how findViewById(R.id.item_detail_container) != null
will ever return true since it never seems to be opened/inflated.
Any clues?
After much looking, the answer is because of this in values-large/refs.xml
<resources>
<item type="layout" name="activity_item_list">@layout/activity_item_twopane</item>
</resources>
It redirects the request for the normal layout to a larger layout (the two-pane version) where R.id.item_detail_container
is defined.
This is pretty obfuscated. I'm not sure why they didn't just call the large layout the same as the normal layout but then have different xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With