I add header and footer views to my listview on activity creation:

        public void onCreate(final Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
...
                this.headerView = new TextView(this);
                this.headerView.setText(null);
                getListView().addHeaderView(headerView, null, false);
                this.footerView = new TextView(this);
                this.footerView.setText(null);
                getListView().addFooterView(footerView, null, false);
                setListAdapter(new SimpleAdapter(this, this.application
                                .getListAdapterData(), 
android.R.layout.simple_list_item_2,
                                new String[] { "name", "directions" }, new 
int[] {
                                                android.R.id.text1, 
android.R.id.text2 }));
        }


I only update the text of the views from a Handler:

        private final Handler handler = new Handler() {
                @Override
                public void handleMessage(final Message msg)
                {
...
                        myActivity.this.headerView.setText("some text");
                        myActivity.this.footerView.setText("some other text");
                        final SimpleAdapter simpleAdapter = (SimpleAdapter) 
getListAdapter
();
                        simpleAdapter.notifyDataSetChanged();
                }
        };

Yet maybe 20% of the time, I get an Exception and the activity dies:

Stack Trace:
D/AndroidRuntime(15300): Shutting down VM
W/dalvikvm(15300): threadid=3: thread exiting with uncaught exception
(group=0x4000fe70)
E/AndroidRuntime(15300): Uncaught handler: thread main exiting due to
uncaught exception
E/AndroidRuntime(15300): java.lang.IndexOutOfBoundsException: Invalid
location 0, size is 0
E/AndroidRuntime(15300): at java.util.ArrayList.get(ArrayList.java:
353)
E/AndroidRuntime(15300): at
android.widget.HeaderViewListAdapter.isEnabled
(HeaderViewListAdapter.java:136)
E/AndroidRuntime(15300): at android.widget.ListView.dispatchDraw
(ListView.java:2784)
E/AndroidRuntime(15300): at android.view.View.draw(View.java:5944)
E/AndroidRuntime(15300): at android.widget.AbsListView.draw
(AbsListView.java:2121)
E/AndroidRuntime(15300): at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime(15300): at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime(15300): at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime(15300): at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime(15300): at android.view.View.draw(View.java:5841)
E/AndroidRuntime(15300): at android.widget.FrameLayout.draw
(FrameLayout.java:352)
E/AndroidRuntime(15300): at android.view.ViewGroup.drawChild
(ViewGroup.java:1486)
E/AndroidRuntime(15300): at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime(15300): at android.view.ViewGroup.drawChild
(ViewGroup.java:1484)
E/AndroidRuntime(15300): at android.view.ViewGroup.dispatchDraw
(ViewGroup.java:1228)
E/AndroidRuntime(15300): at android.view.View.draw(View.java:5841)
E/AndroidRuntime(15300): at android.widget.FrameLayout.draw
(FrameLayout.java:352)
E/AndroidRuntime(15300): at
com.android.internal.policy.impl.PhoneWindow$DecorView.draw
(PhoneWindow.java:1847)
E/AndroidRuntime(15300): at android.view.ViewRoot.draw(ViewRoot.java:
1217)
E/AndroidRuntime(15300): at android.view.ViewRoot.performTraversals
(ViewRoot.java:1030)
E/AndroidRuntime(15300): at android.view.ViewRoot.handleMessage
(ViewRoot.java:1482)
E/AndroidRuntime(15300): at android.os.Handler.dispatchMessage
(Handler.java:99)
E/AndroidRuntime(15300): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(15300): at android.app.ActivityThread.main
(ActivityThread.java:3948)
E/AndroidRuntime(15300): at java.lang.reflect.Method.invokeNative
(Native Method)
E/AndroidRuntime(15300): at java.lang.reflect.Method.invoke
(Method.java:521)
E/AndroidRuntime(15300): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime(15300): at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:540)
E/AndroidRuntime(15300): at dalvik.system.NativeStart.main(Native
Method)
I/Process (   59): Sending signal. PID: 15300 SIG: 3

My code is nowhere in that stack trace.
It feels like there may be some synchronization problems in the
backing list or adapter for header and footer views?
This is running on a Donut release.

Thanks for any help
...bjc

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to