Java Code Examples for android.widget.ListAdapter#registerDataSetObserver()

The following examples show how to use android.widget.ListAdapter#registerDataSetObserver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DragSortListView.java    From chromadoze with GNU General Public License v3.0 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate set*Listener
 * method with <code>adapter</code> as the argument.
 * 
 * @param adapter
 *            The ListAdapter providing data to back DragSortListView.
 * 
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 2
Source File: DragSortListView.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 * 
 * @param adapter The ListAdapter providing data to back
 * DragSortListView.
 *
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 3
Source File: PinnedSectionListView.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {

    // assert adapter in debug mode
	if (BuildConfig.DEBUG && adapter != null) {
		if (!(adapter instanceof PinnedSectionListAdapter))
			throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
		if (adapter.getViewTypeCount() < 2)
			throw new IllegalArgumentException("Does your adapter handle at least two types" +
					" of views in getViewTypeCount() method: items and sections?");
	}

	// unregister observer at old adapter and register on new one
	ListAdapter oldAdapter = getAdapter();
	if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver);
	if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver);

	// destroy pinned shadow, if new adapter is not same as old one
	if (oldAdapter != adapter) destroyPinnedShadow();

	super.setAdapter(adapter);
}
 
Example 4
Source File: DragSortListView.java    From android-kernel-tweaker with GNU General Public License v3.0 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 * 
 * @param adapter The ListAdapter providing data to back
 * DragSortListView.
 *
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 5
Source File: AdapterWrapper.java    From Android-Next with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor wrapping a supplied ListAdapter
 */
public AdapterWrapper(ListAdapter wrapped) {
    super();

    this.wrapped = wrapped;

    wrapped.registerDataSetObserver(new DataSetObserver() {
        public void onChanged() {
            notifyDataSetChanged();
        }

        public void onInvalidated() {
            notifyDataSetInvalidated();
        }
    });
}
 
Example 6
Source File: DragSortListView.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 * 
 * @param adapter The ListAdapter providing data to back
 * DragSortListView.
 *
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 7
Source File: ListPopupWindow.java    From material with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the adapter that provides the data and the views to represent the data
 * in this popup window.
 *
 * @param adapter The adapter to use to create this window's content.
 */
public void setAdapter(ListAdapter adapter) {
    if (mObserver == null) {
        mObserver = new PopupDataSetObserver();
    } else if (mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mObserver);
    }
    mAdapter = adapter;
    if (mAdapter != null) {
        adapter.registerDataSetObserver(mObserver);
    }

    if (mDropDownList != null) {
        mDropDownList.setAdapter(mAdapter);
    }
}
 
Example 8
Source File: DragSortListView.java    From DongWeather with Apache License 2.0 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 * 
 * @param adapter The ListAdapter providing data to back
 * DragSortListView.
 *
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 9
Source File: PinnedSectionListView.java    From AndroidWeekly with Apache License 2.0 6 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {

    // assert adapter in debug mode
    if (BuildConfig.DEBUG && adapter != null) {
        if (!(adapter instanceof PinnedSectionListAdapter))
            throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
        if (adapter.getViewTypeCount() < 2)
            throw new IllegalArgumentException("Does your adapter handle at least two types" +
                    " of views in getViewTypeCount() method: items and sections?");
    }

    // unregister observer at old adapter and register on new one
    ListAdapter oldAdapter = getAdapter();
    if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver);
    if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver);

    // destroy pinned shadow, if new adapter is not same as old one
    if (oldAdapter != adapter) destroyPinnedShadow();

    super.setAdapter(adapter);
}
 
Example 10
Source File: DragSortListView.java    From google-authenticator-android with Apache License 2.0 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 * 
 * @param adapter The ListAdapter providing data to back
 * DragSortListView.
 *
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 11
Source File: ListPopupWindow.java    From MDPreference with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the adapter that provides the data and the views to represent the data
 * in this popup window.
 *
 * @param adapter The adapter to use to create this window's content.
 */
public void setAdapter(ListAdapter adapter) {
    if (mObserver == null) {
        mObserver = new PopupDataSetObserver();
    } else if (mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mObserver);
    }
    mAdapter = adapter;
    if (mAdapter != null) {
        adapter.registerDataSetObserver(mObserver);
    }

    if (mDropDownList != null) {
        mDropDownList.setAdapter(mAdapter);
    }
}
 
Example 12
Source File: DragSortListView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 * 
 * @param adapter The ListAdapter providing data to back
 * DragSortListView.
 *
 * @see android.widget.ListView#setAdapter(android.widget.ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 13
Source File: PinnedSectionListView.java    From PullToRefresh-PinnedSection-ListView with MIT License 6 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {

    // assert adapter in debug mode
	if (BuildConfig.DEBUG && adapter != null) {
		if (!(adapter instanceof PinnedSectionListAdapter))
			throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
		if (adapter.getViewTypeCount() < 2)
			throw new IllegalArgumentException("Does your adapter handle at least two types" +
					" of views in getViewTypeCount() method: items and sections?");
	}

	// unregister observer at old adapter and register on new one
	ListAdapter oldAdapter = getAdapter();
	if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver);
	if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver);

	// destroy pinned shadow, if new adapter is not same as old one
	if (oldAdapter != adapter) destroyPinnedShadow();

	super.setAdapter(adapter);
}
 
Example 14
Source File: CardContainer.java    From giraff-android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {
	if (mListAdapter != null)
		mListAdapter.unregisterDataSetObserver(mDataSetObserver);

	clearStack();
	mTopCard = null;
	mListAdapter = adapter;
	mNextAdapterPosition = 0;
	adapter.registerDataSetObserver(mDataSetObserver);

	ensureFull();

	if (getChildCount() != 0) {
		mTopCard = getChildAt(getChildCount() - 1);
		mTopCard.setLayerType(LAYER_TYPE_HARDWARE, null);
	}
       mNumberOfCards = getAdapter().getCount();
	requestLayout();
}
 
Example 15
Source File: RollbackSectionListAdapter.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public RollbackSectionListAdapter(final LayoutInflater inflater,
                                  final ListAdapter linkedAdapter) {
    this.linkedAdapter = linkedAdapter;
    this.inflater = inflater;
    linkedAdapter.registerDataSetObserver(dataSetObserver);
    updateSessionCache();
}
 
Example 16
Source File: AutoCompleteListView.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setAdapter(final ListAdapter adapter) {
    super.setAdapter(adapter);
    adapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            updateEmptyView();
        }
    });
}
 
Example 17
Source File: IcsListPopupWindow.java    From android-apps with MIT License 5 votes vote down vote up
public void setAdapter(ListAdapter adapter) {
    if (mObserver == null) {
        mObserver = new PopupDataSetObserver();
    } else if (mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mObserver);
    }
    mAdapter = adapter;
    if (mAdapter != null) {
        adapter.registerDataSetObserver(mObserver);
    }

    if (mDropDownList != null) {
        mDropDownList.setAdapter(mAdapter);
    }
}
 
Example 18
Source File: AnimationListView.java    From AnimationListView with Apache License 2.0 4 votes vote down vote up
public AdapterWrapper(final ListAdapter adapter) {
	this.adapter = adapter;

	adapter.registerDataSetObserver(observer);
}
 
Example 19
Source File: StickyGridHeadersListAdapterWrapper.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public StickyGridHeadersListAdapterWrapper(ListAdapter adapter) {
    mDelegate = adapter;
    if (adapter != null) {
        adapter.registerDataSetObserver(mDataSetObserver);
    }
}
 
Example 20
Source File: MergeAdapter.java    From SimpleExplorer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds a new adapter to the roster of things to appear in the aggregate
 * list.
 *
 * @param adapter Source for row views for this section
 */
public void addAdapter(ListAdapter adapter) {
    pieces.add(adapter);
    adapter.registerDataSetObserver(new CascadeDataSetObserver());
}