Note that there are some explanatory texts on larger screens.

plurals
  1. PONavigation Drawer - Create New Fragment Instance every time or simply "refresh" data
    primarykey
    data
    text
    <p>I'm having a bit of an argument with myself and I wanted to check with the rest of you which implementation is "best" in terms of better practices.</p> <p>Just like a basic Navigation Drawer app, mine has one main NavDrawerActivity that contains the NavDrawer itself, and a Frame Layout that I later replace. Then, I also have one Fragment called ListsFragment, that basically contains a ListView of data from a simple String ArrayList. Therefore, this ListsFragment <strong>always</strong> contains a basic list of Strings (meaning, I only ever need one fragment.java file).</p> <p>Now, in Google's example of the Navigation Drawer, they have something similar, where they have one Fragment that they simply replace with new content (replace as in, literally, FragmentManager.replace(etc)). This means that a new Fragment is reinstantiated each time we select an item from the NavDrawer. <strong>This is what I'm doing right now as well.</strong></p> <p>But I've been thinking whether or not doing this is "messy". Won't a cleaner way of doing this be:</p> <p>Create a method in the Fragment called <code>loadList(ArrayList&lt;String&gt; list)</code>, which basically replaces the contents of the ListView in the Fragment with the consumed list.</p> <p>After all, isn't this a "cheaper" operation cost than having to instantiate a new Fragment everytime? When I could just be "refreshing" the data through a single Fragment variable I'll maintain?</p> <p>So, my question is: Which is better? Or if "better" is too subjective: Which is more, "the Java/Android way". It'd be great to see what you think. Thanks!</p> <p><strong>TLDR:</strong> Which is better: Instantiating a new Fragment every time I select a new item from the NavDrawer or simply load new data through a public <code>loadData</code> method.</p> <p>EDIT: For those who want to see Google's NavDrawer example, the Example is downloadable here <a href="http://developer.android.com/training/implementing-navigation/nav-drawer.html" rel="nofollow">http://developer.android.com/training/implementing-navigation/nav-drawer.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload