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.
so if you want to add header view to your listView, you should do that severely before use setListAdapter() or else it causes an IllegalStateException.