views:

1081

answers:

2

I have an app whose main class extends ListActivity:

public class GUIPrototype extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Cursor c = managedQuery(People.CONTENT_URI, null, null, null, null);
        String[] from = new String[] {People.NAME};
        int[] to = new int[] { R.id.row_entry };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.drawer,c,from,to);


        setListAdapter(adapter);
        getListView().setTextFilterEnabled(true);
    }
}

I have a sliding drawer included in my XML, and I'm trying to get a separate listview to appear in the sliding drawer. I'm trying to populate the second listview using an inflater:

View inflatedView = View.inflate(this, R.layout.main, null);
ListView namesLV = (ListView) inflatedView.findViewById(R.id.content);
String[] names2  = new String[] { "CS 345", "New Tag", "Untagged" };
ArrayAdapter<String> bb = new ArrayAdapter<String>(this, R.layout.main, R.id.row_entry, names2);
namesLV.setAdapter(bb);

This compiles, and runs, but the slidingdrawer is completely blank. My XML follows:

<SlidingDrawer
    android:id="@+id/drawer"
    android:handle="@+id/handle"
    android:content="@+id/content"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="bottom">

    <ImageView
        android:id="@id/handle"
        android:layout_width="48px"
        android:layout_height="48px" android:background="@drawable/icon"/>

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@id/content"/>
</SlidingDrawer>

I feel like I'm missing a vital step. I haven't found any resources on my problem by Googling, so any help would be greatly appreciated.

A: 

It looks like the problem could be that you are inflating a new instance of a ListView rather than using the one in your view.

Try getting the ListView with ListView listView = (ListView) findViewById(R.id.content);

Then apply your adapter to it.

disretrospect
Either combination results in a NullPointerException, sadly.
Parker
A: 

Have you tried

View inflatedView = View.inflate(this, R.layout.main, null);
SlidingDrawer sliding=(SlidingDrawer) inflatedView.findViewById(R.id.drawer);
ListView namesLV = (ListView) sliding.findViewById(R.id.content);
gogothee