Android Source Learning (a) Data set viewer

Source: Internet
Author: User

View Android source found this, decided to write down.

1. Under Android.database This package, there is an abstract class Datasetobserver, which includes the onchanged () and oninvalidated () two methods, which are used to listen for changes in the data, the operation to be performed within the method.

/** Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License "); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * *http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable or agreed to writing, software * Distributed under the License is distribute D on ' As is ' BASIS, * without warranties or CONDITIONS of any KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */Package android.database;/** * Receives call backs if a data set has been changed, or made invalid.  The typically data sets * that is observed is {@link cursor}s or {@link android.widget.adapter}s. * Datasetobserver must be implemented by objects which is added to a datasetobservable. */ Public Abstract classDatasetobserver {/** * This method was called when the entire data set have changed, * most likely through a call to {@link cursor#     Requery ()} on a {@link Cursor}. */     Public voidonChanged () {// do nothing    }    /** * This method was called when the entire data becomes invalid, * Most likely through a call to {@link cursor#     Deactivate ()} or {@link cursor#close ()} on a * {@link Cursor}. */     Public voidoninvalidated () {// do nothing    }}

2. A class such as observable exists in the sibling directory if the above datasetobserver is used as the generic parameter for this class.

/** Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License "); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * *http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable or agreed to writing, software * Distributed under the License is distribute D on ' As is ' BASIS, * without warranties or CONDITIONS of any KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */Package Android.database;import java.util.ArrayList;/** * provides methods for registering or unregistering arbitrary observers in a {@link ArrayList}. * * This abstract C Lass is intended to being subclassed and specialized to maintain * a registry of observers of specific types and dispatch not Ifications to them. * * @param T the Observer type. */ Public Abstract classObservable<t> {    /** * The list of observers.     An observer can is in the list at most * once and would never be null. */    protectedFinal arraylist<t> mobservers =NewArraylist<t>(); /** * ADDS an observer to the list.     The observer cannot is null and it must not already * is registered. * @param observer The Observer to register * @throws ILLEGALARGUMENTEXCEPTION The Observer is NULL * @throws Illeg Alstateexception The Observer is already registered*/     Public voidRegisterobserver (T observer) {if(Observer = =NULL) {            Throw NewIllegalArgumentException ("The observer is null."); } synchronized (mobservers) {if(Mobservers.contains (Observer)) {Throw NewIllegalStateException ("Observer"+ Observer +"is already registered.");        } MOBSERVERS.ADD (Observer); }    }    /** * Removes a previously registered observer.     The observer must not being null and it * must already has been registered. * @param observer The Observer to unregister * @throws ILLEGALARGUMENTEXCEPTION The Observer is NULL * @throws ILL Egalstateexception The Observer is not yet registered*/     Public voidUnregisterobserver (T observer) {if(Observer = =NULL) {            Throw NewIllegalArgumentException ("The observer is null."); } synchronized (mobservers) {intindex =MOBSERVERS.INDEXOF (Observer); if(Index = =-1) {                Throw NewIllegalStateException ("Observer"+ Observer +"Was is not registered.");        } mobservers.remove (index); }    }    /** * Remove all registered observers. */     Public voidUnregisterAll () {synchronized (mobservers) {mobservers.clear (); }    }}

Android Source Learning (a) Data set viewer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.