2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.support.v2.widget;
19 import android.content.Context;
20 import android.database.Cursor;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.view.LayoutInflater;
26 * Static library support version of the framework's {@link android.widget.ResourceCursorAdapter}.
27 * Used to write apps that run on platforms prior to Android 3.0. When running
28 * on Android 3.0 or above, this implementation is still used; it does not try
29 * to switch to the framework's implementation. See the framework SDK
30 * documentation for a class overview.
32 public abstract class ResourceCursorAdapter extends CursorAdapter {
35 private int mDropDownLayout;
37 private LayoutInflater mInflater;
40 * Constructor the enables auto-requery.
42 * @deprecated This option is discouraged, as it results in Cursor queries
43 * being performed on the application's UI thread and thus can cause poor
44 * responsiveness or even Application Not Responding errors. As an alternative,
45 * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}.
47 * @param context The context where the ListView associated with this adapter is running
48 * @param layout resource identifier of a layout file that defines the views
49 * for this list item. Unless you override them later, this will
50 * define both the item views and the drop down views.
53 public ResourceCursorAdapter(Context context, int layout, Cursor c) {
55 mLayout = mDropDownLayout = layout;
56 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
60 * Constructor with default behavior as per
61 * {@link CursorAdapter#CursorAdapter(Context, Cursor, boolean)}; it is recommended
62 * you not use this, but instead {@link #ResourceCursorAdapter(Context, int, Cursor, int)}.
63 * When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER}
66 * @param context The context where the ListView associated with this adapter is running
67 * @param layout resource identifier of a layout file that defines the views
68 * for this list item. Unless you override them later, this will
69 * define both the item views and the drop down views.
70 * @param c The cursor from which to get the data.
71 * @param autoRequery If true the adapter will call requery() on the
72 * cursor whenever it changes so the most recent
73 * data is always displayed. Using true here is discouraged.
75 public ResourceCursorAdapter(Context context, int layout, Cursor c, boolean autoRequery) {
76 super(context, c, autoRequery);
77 mLayout = mDropDownLayout = layout;
78 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
82 * Standard constructor.
84 * @param context The context where the ListView associated with this adapter is running
85 * @param layout Resource identifier of a layout file that defines the views
86 * for this list item. Unless you override them later, this will
87 * define both the item views and the drop down views.
88 * @param c The cursor from which to get the data.
89 * @param flags Flags used to determine the behavior of the adapter,
90 * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}.
92 public ResourceCursorAdapter(Context context, int layout, Cursor c, int flags) {
93 super(context, c, flags);
94 mLayout = mDropDownLayout = layout;
95 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
99 * Inflates view(s) from the specified XML file.
101 * @see android.widget.CursorAdapter#newView(android.content.Context,
102 * android.database.Cursor, ViewGroup)
105 public View newView(Context context, Cursor cursor, ViewGroup parent) {
106 return mInflater.inflate(mLayout, parent, false);
110 public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) {
111 return mInflater.inflate(mDropDownLayout, parent, false);
115 * <p>Sets the layout resource of the item views.</p>
117 * @param layout the layout resources used to create item views
119 public void setViewResource(int layout) {
124 * <p>Sets the layout resource of the drop down views.</p>
126 * @param dropDownLayout the layout resources used to create drop down views
128 public void setDropDownViewResource(int dropDownLayout) {
129 mDropDownLayout = dropDownLayout;