views:

108

answers:

2

Hi,

I have a class that is called when my app launches.

public class MainActivity extends Activity implements NetworkEvent.

In this situation,

list = (ListView) findViewById(R.id.list);

works perfectly. However if I then call a new intent via:

   String[] names = object.names();

Intent myIntent = new Intent(MainActivity.this, SimpleList.class); myIntent.putExtra("names", names); startActivityForResult(myIntent, 0);

where SimpleList is defined as:

public class SimpleList extends ListActivity implements NetworkEvent

then when I call

   list=(ListView) findViewById(R.id.list);

Log.i("MyApp", "List:" + list);

from within the SimpleList class, list is null :(

How come? Both classes are within the same package.

Thanks.

+1  A: 

I'm not exactly sure why it's happening in your case, but the ListView in your layout XML must be defined as <ListView android:id="@android:id/list", not the typical <ListView android:id="@+id/list" if your class extends ListActivity. In that case, you just use getListView() to access the list. Check out http://developer.android.com/reference/android/app/ListActivity.html

cfei
Great! Thank you so much, this was it!
Dave
+1  A: 

Make sure you call setContentView(R.whatever) before you can find any ids in it.

Maaalte