Note that there are some explanatory texts on larger screens.

plurals
  1. POUse XML resource in List Fragment generated with Eclipse
    text
    copied!<p>I've generated a new List Fragment using Eclipse (<em>New -> Android Object -> New List Fragment</em>) which creates <code>ItemFragment</code> and <code>dummy.DummyContent</code> Classes.</p> <p>I have 2 questions regarding this:</p> <ol> <li><p>More of a general question... How is the DummyContent instantiated? Is the declaration of the ArrayAdapter doing the work? As I don't see anywhere in the code a new DummyContent. see below:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TODO: Change Adapter to display your content mAdapter = new ArrayAdapter&lt;DummyContent.DummyItem&gt;(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS); } </code></pre></li> <li><p>In the DummyContent class, I would like to populate the <code>ArrayList&lt;DummyItem&gt; ITEMS</code> with data pulled from a Resource XML file, however it seems since I don't the <code>Context</code> in this DummyContent class, I can't access <code>R.xml.*</code> Is there a way to pass the context to that class somehow?</p> <pre><code>public class DummyContent { /** * An array of sample (dummy) items. */ public static List&lt;DummyItem&gt; ITEMS = new ArrayList&lt;DummyItem&gt;(); /** * A map of sample (dummy) items, by ID. */ public static Map&lt;String, DummyItem&gt; ITEM_MAP = new HashMap&lt;String, DummyItem&gt;(); static { // Add 3 sample items. addItem(new DummyItem("1", "Item 1")); addItem(new DummyItem("2", "Item 2")); addItem(new DummyItem("3", "Item 3")); } private static void addItem(DummyItem item) { ITEMS.add(item); ITEM_MAP.put(item.id, item); } /** * A dummy item representing a piece of content. */ public static class DummyItem { public String id; public String content; public DummyItem(String id, String content) { this.id = id; this.content = content; } @Override public String toString() { return content; } } } </code></pre></li> </ol> <p>Thanks in advance and let me know if there is anything unclear in the question. </p>
 

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