Android - ListActivity, add Header and Footer view
Posted
by
Victor
on Stack Overflow
See other posts from Stack Overflow
or by Victor
Published on 2012-04-15T15:06:32Z
Indexed on
2012/04/15
17:29 UTC
Read the original article
Hit count: 343
I'm using ListActivity, listview.
listView = getListView();
just working perfectly. I added footer view as
LayoutInflater inflater = getLayoutInflater();
listView.addFooterView( inflater.inflate( R.layout.footer, null ), null, false);
and everything was shiny but ugly, so i wanted to add this footer view (which contains only 1 edittext and only 1 button ) to header of listView as
LayoutInflater inflater = getLayoutInflater();
listView.addHeaderView( inflater.inflate( R.layout.footer, null ), null, false);
and suddenly everything goes wrong, and i get RuntimeException immediately.
Suspended(exception RuntimeException)
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent)
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent)
ActivityThread.access$2200(ActivityThread, Activity$ActiviyRecord, Intent),
so on..
Why is it throws exception ? What is different between addFooterView and addHeaderView, and how can i add Header to ListActivity ?
UPDATE
So as you can read in comments, my logcat still doesn't work, but i just tried next at this moment:
} catch(Exception e){
Writer result = new StringWriter();
PrintWriter printWriter = new PrintWriter(result);
e.printStackTrace(printWriter);
String error = result.toString();
}
and afterward i put breakpoint, and i can read error in expressions section. it said :
java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.
it was instructive for all of us. After change sort of commands, it works perferctly.
© Stack Overflow or respective owner