Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two questions about Master/Detail Flow Template

Tags:

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?

like image 279
Mike T Avatar asked Jul 10 '12 13:07

Mike T


1 Answers

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.

like image 50
Mike T Avatar answered Nov 25 '22 02:11

Mike T