blob: 27cf9a64a8d5ce13bfaeddce216ac8a18bf80bd7 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.widget;
18
Felipe Leme49a38c62017-06-13 12:51:43 -070019import android.annotation.Nullable;
Artur Satayevad9254c2019-12-10 17:47:54 +000020import android.compat.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.database.DataSetObservable;
22import android.database.DataSetObserver;
23import android.view.View;
24import android.view.ViewGroup;
25
26/**
27 * Common base class of common implementation for an {@link Adapter} that can be
28 * used in both {@link ListView} (by implementing the specialized
Newton Allenc5027442013-08-13 11:22:32 -070029 * {@link ListAdapter} interface) and {@link Spinner} (by implementing the
30 * specialized {@link SpinnerAdapter} interface).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031 */
32public abstract class BaseAdapter implements ListAdapter, SpinnerAdapter {
Mathew Inwood978c6e22018-08-21 15:58:55 +010033 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 private final DataSetObservable mDataSetObservable = new DataSetObservable();
Felipe Leme49a38c62017-06-13 12:51:43 -070035 private CharSequence[] mAutofillOptions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37 public boolean hasStableIds() {
38 return false;
39 }
40
41 public void registerDataSetObserver(DataSetObserver observer) {
42 mDataSetObservable.registerObserver(observer);
43 }
44
45 public void unregisterDataSetObserver(DataSetObserver observer) {
46 mDataSetObservable.unregisterObserver(observer);
47 }
48
49 /**
Adam Powellf5d412a2011-09-27 11:32:59 -070050 * Notifies the attached observers that the underlying data has been changed
51 * and any View reflecting the data set should refresh itself.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 */
53 public void notifyDataSetChanged() {
54 mDataSetObservable.notifyChanged();
55 }
Adam Powellf5d412a2011-09-27 11:32:59 -070056
57 /**
58 * Notifies the attached observers that the underlying data is no longer valid
59 * or available. Once invoked this adapter is no longer valid and should
60 * not report further data set changes.
61 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 public void notifyDataSetInvalidated() {
63 mDataSetObservable.notifyInvalidated();
64 }
65
66 public boolean areAllItemsEnabled() {
67 return true;
68 }
69
70 public boolean isEnabled(int position) {
71 return true;
72 }
73
74 public View getDropDownView(int position, View convertView, ViewGroup parent) {
75 return getView(position, convertView, parent);
76 }
77
78 public int getItemViewType(int position) {
79 return 0;
80 }
81
82 public int getViewTypeCount() {
83 return 1;
84 }
85
86 public boolean isEmpty() {
87 return getCount() == 0;
88 }
Felipe Leme49a38c62017-06-13 12:51:43 -070089
90 @Override
91 public CharSequence[] getAutofillOptions() {
92 return mAutofillOptions;
93 }
94
95 /**
96 * Sets the value returned by {@link #getAutofillOptions()}
97 */
98 public void setAutofillOptions(@Nullable CharSequence... options) {
99 mAutofillOptions = options;
100 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101}