Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 22c04a31 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Fix bugs in ListView

Make addHeaderView and addFooterView be more consistent with each other: they
now both check that there either is no existing adapter, or that the existing
adapter is a HeaderViewListAdapter, and they both call the DataSetObserver
(previously only addHeaderView would check the adapter, and it would only
check that it was null, while only addFooterView would call the DataSetObserver)
Make removeHeaderView and removeFooterView check that the DataSetObserver
is non-null before using it.

Change-Id: I681b87f70aabca63e664ca8d0c1cfc25530e00b9
parent 08d1f937
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -251,7 +251,7 @@ public class ListView extends AbsListView {
     */
    public void addHeaderView(View v, Object data, boolean isSelectable) {

        if (mAdapter != null) {
        if (mAdapter != null && ! (mAdapter instanceof HeaderViewListAdapter)) {
            throw new IllegalStateException(
                    "Cannot add header view to list -- setAdapter has already been called.");
        }
@@ -261,6 +261,12 @@ public class ListView extends AbsListView {
        info.data = data;
        info.isSelectable = isSelectable;
        mHeaderViewInfos.add(info);

        // in the case of re-adding a header view, or adding one later on,
        // we need to notify the observer
        if (mDataSetObserver != null) {
            mDataSetObserver.onChanged();
        }
    }

    /**
@@ -294,7 +300,9 @@ public class ListView extends AbsListView {
        if (mHeaderViewInfos.size() > 0) {
            boolean result = false;
            if (((HeaderViewListAdapter) mAdapter).removeHeader(v)) {
                if (mDataSetObserver != null) {
                    mDataSetObserver.onChanged();
                }
                result = true;
            }
            removeFixedViewInfo(v, mHeaderViewInfos);
@@ -328,6 +336,12 @@ public class ListView extends AbsListView {
     * @param isSelectable true if the footer view can be selected
     */
    public void addFooterView(View v, Object data, boolean isSelectable) {

        if (mAdapter != null && ! (mAdapter instanceof HeaderViewListAdapter)) {
            throw new IllegalStateException(
                    "Cannot add footer view to list -- setAdapter has already been called.");
        }

        FixedViewInfo info = new FixedViewInfo();
        info.view = v;
        info.data = data;
@@ -371,7 +385,9 @@ public class ListView extends AbsListView {
        if (mFooterViewInfos.size() > 0) {
            boolean result = false;
            if (((HeaderViewListAdapter) mAdapter).removeFooter(v)) {
                if (mDataSetObserver != null) {
                    mDataSetObserver.onChanged();
                }
                result = true;
            }
            removeFixedViewInfo(v, mFooterViewInfos);