Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomize the ListView in a Fragment-based Master-Detail Flow?
    primarykey
    data
    text
    <p>I found the template that ADT generates for a Master/Detail Flow Activity to be rather obtuse, and I don't like the fact that the ListView is not declared in a layout file which forces me to work with it programatically. For example, instead of just setting <code>android:background</code> on the ListView in a layout file, I'm forced to find the ListView via findViewById in the fragment's <code>onCreateView(...)</code> method, then call <code>setBackground(...)</code>. For maintainability and general readability, I'd like to do the same thing via a layout file.</p> <p>Instead, I'm trying to inflate a custom layout in the <code>onCreateView</code> method of the "master" fragment:</p> <pre><code>public class InboxFragment extends ListFragment { public InboxFragment() {} private ListView listView = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { listView = (ListView) inflater.inflate(R.layout.inbox_fragment_layout, null); return listView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // the following doesn't work listView.setAdapter(new ArrayAdapter&lt;DummyContent.DummyItem&gt;(getActivity(), android.R.layout.simple_list_item_activated_1, android.R.id.text1, DummyContent.ITEMS)); // nor does this //setListAdapter(new ArrayAdapter&lt;DummyContent.DummyItem&gt;(getActivity(), // android.R.layout.simple_list_item_activated_1, // android.R.id.text1, // DummyContent.ITEMS)); } } </code></pre> <p>However, calling <code>setListAdapter</code> (or even <code>setAdapter</code>) doesn't seem to do anything, even though I've given the ListView an id of <code>android:id="@id/android:list"</code> in <code>R.layout.inbox_fragment_layout</code>:</p> <pre><code>&lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#D3D3D3" /&gt; </code></pre> <p>My "master" activity just calls a fragment layout:</p> <pre><code>public class InboxActivity extends FragmentActivity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.inbox_phone_layout); } } </code></pre> <p>inbox_phone_layout.xml:</p> <pre><code>&lt;fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragmentPhoneInbox" android:name="com.justin.inbox.InboxFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /&gt; </code></pre> <p>Instead, I'm greeted with a blank page and it doesn't look like the ListView is loaded at all. What am I doing wrong, here? <a href="https://github.com/justingarrick/fragmented-master-detail" rel="nofollow">Sample project on GitHub</a>.</p>
    singulars
    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.
 

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