Office Hours — Today, February 2

Tuesday, January 31

Mark M.
has entered the room
Mark M.
turned on guest access
Tawanna
has entered the room
Tawanna
Hi Mark, how are you?
Mark M.
howdy, Tawanna!
how can I help you today?
Tawanna
View paste
Yes, 
I'm setting up a list activity for my project and I've implemented my own adapter (following the tutorial http://www.vogella.de/articles/AndroidListView/article.html). I've also followed the instructions to optimize my adapter performance (6.2). 

I'm having trouble understanding instructions to implement a header and footer around my ListView. The only xml file that I have created is the rowlayout which defines the structure of each rows within the view. I'm not sure where to define the header and footer elements or where to specify the @android:id/list id. Most of the tutorials I've seen about this don't mention how to do this for custom adapters/list but for basic ListViews.

Could you help me to understand how to create a header/footer for a customized list? I have been following 6. Tutorial: Implementing your own adapter from the vogella page and 9. Header and Footer but the Header and Footer example assumes a basic ListView.
Feb 2
10:00 AM
Mark M.
when you say "header" and "footer", should they be scrolling with the list contents, or are they supposed to stay fixed on the screen?
Tawanna
They are static
Mark M.
then the chapter and tutorials you are reading are not what you want
certainly, not mine
those are for what *Android* refers to as headers and footers, which scroll with the list contents
for static headers and footers, put them outside of the ListView
for example, have a LinearLayout that holds the header, the ListView, and the footer
use android:layout_weight properly to have the ListView fill all space not needed by the header and footer
Tawanna
ok. this may be a silly question but what links the listview to the actual row layout?
Mark M.
the adapter
Tawanna
right now, i don't have an actual list view layout defined
Mark M.
well, if you are using ListActivity or ListFragment, you do not ordinarily need a layout for the overall activity or fragment
in your case, though, you do, as you want to have more than just a ListView
so, you create a layout and call setContentView() for the ListActivity, or implement onCreateView() in ListFragment
in that layout, you need a ListView whose ID is @android:id/list
Tawanna
okay, that was something i didn't quite understand. the adapter will know based on that id
Mark M.
not really
10:05 AM
Mark M.
let's simplify matters: are you using ListFragment, ListActivity, or something else?
Tawanna
ListActivity
Mark M.
OK
ListActivity is an activity
activities have a content view
Tawanna
right
Mark M.
that content view is normally set via setContentView()
ListActivity will call setContentView() for you if needed, for a full-screen ListView
in your case, you will call setContentView() yourself
you **also** need to call setListAdapter()
this will tell the ListActivity (who tells the ListView) what ListAdapter is to be used for the rows
the ListAdapter you supply to setListAdapter() determines what the rows look like
Tawanna
okay! now i see the connection!
thank you!
Mark M.
you may wish to read the "Getting Fancy with Lists" chapter from _The Busy Coder's Guide to Android Development_, and perhaps the preceding chapter ("Using Selection Widgets"), for more on this subject
Tawanna
Awesome! Thank you!
10:10 AM
Mark M.
do you have another question?
Tawanna
no, that's all for now
Mark M.
OK, if you think of anything, chime in
Tawanna
will do
10:55 AM
Mark M.
just about the end of the chat -- any final questions?
Tawanna
no, thanks for your help!
11:00 AM
Tawanna
enjoy the rest of your day!
Mark M.
you too!
next chat is Wednesday, 7:30pm Eastern
Tawanna
ok!
Tawanna
has left the room
Mark M.
turned off guest access

Tuesday, January 31

 

Office Hours

People in this transcript

  • Mark Murphy
  • Tawanna