The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.widget; |
| 18 | |
| 19 | import android.database.DataSetObservable; |
| 20 | import android.database.DataSetObserver; |
| 21 | import android.view.View; |
| 22 | import android.view.ViewGroup; |
| 23 | |
| 24 | /** |
| 25 | * Common base class of common implementation for an {@link Adapter} that can be |
| 26 | * used in both {@link ListView} (by implementing the specialized |
Newton Allen | c502744 | 2013-08-13 11:22:32 -0700 | [diff] [blame] | 27 | * {@link ListAdapter} interface) and {@link Spinner} (by implementing the |
| 28 | * specialized {@link SpinnerAdapter} interface). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | */ |
| 30 | public abstract class BaseAdapter implements ListAdapter, SpinnerAdapter { |
| 31 | private final DataSetObservable mDataSetObservable = new DataSetObservable(); |
| 32 | |
| 33 | public boolean hasStableIds() { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | public void registerDataSetObserver(DataSetObserver observer) { |
| 38 | mDataSetObservable.registerObserver(observer); |
| 39 | } |
| 40 | |
| 41 | public void unregisterDataSetObserver(DataSetObserver observer) { |
| 42 | mDataSetObservable.unregisterObserver(observer); |
| 43 | } |
| 44 | |
| 45 | /** |
Adam Powell | f5d412a | 2011-09-27 11:32:59 -0700 | [diff] [blame] | 46 | * Notifies the attached observers that the underlying data has been changed |
| 47 | * and any View reflecting the data set should refresh itself. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | */ |
| 49 | public void notifyDataSetChanged() { |
| 50 | mDataSetObservable.notifyChanged(); |
| 51 | } |
Adam Powell | f5d412a | 2011-09-27 11:32:59 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Notifies the attached observers that the underlying data is no longer valid |
| 55 | * or available. Once invoked this adapter is no longer valid and should |
| 56 | * not report further data set changes. |
| 57 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | public void notifyDataSetInvalidated() { |
| 59 | mDataSetObservable.notifyInvalidated(); |
| 60 | } |
| 61 | |
| 62 | public boolean areAllItemsEnabled() { |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | public boolean isEnabled(int position) { |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | public View getDropDownView(int position, View convertView, ViewGroup parent) { |
| 71 | return getView(position, convertView, parent); |
| 72 | } |
| 73 | |
| 74 | public int getItemViewType(int position) { |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | public int getViewTypeCount() { |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | public boolean isEmpty() { |
| 83 | return getCount() == 0; |
| 84 | } |
| 85 | } |