Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Standard ListViews Displaying List Data (or None At All)

Yuchen Xu
PLUS
Yuchen Xu
Courses Plus Student 1,965 Points

What if you have Multiple ListViews that you would like to use ListActivity for?

Could different ListView have the same ID @android:id/list then?

I would just manage the lists myself. ListActivity doesn't really do that much. For instance setListAdapter just calls setAdapter on a ListView item is got by using findViewById. Assume you have a layout file that has two ListView items with ids listView1 and listView2. In onCreate you would do something like

ListView listView1 = findViewById(R.id.listView1 ); listView1.setAdapter(new ArrayAdapter ...

ListView listView2 = findViewById(R.id.listView2 ); listView2.setAdapter(new ArrayAdapter ...

Yuchen Xu
Yuchen Xu
Courses Plus Student 1,965 Points

Yea, that's what I feel as well. Seems like ListAcitivity is only used for saving a couple lines of initialization code, but that advantage goes away when we have multiple listviews to manager. Good to know !