blob: 7341c2c5d31937b3e0af593190c1b54136793d75 [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
19import android.content.Context;
20import android.database.Cursor;
21import android.view.View;
22import android.view.ViewGroup;
23import android.view.LayoutInflater;
24
25
26/**
27 * An easy adapter that creates views defined in an XML file. You can specify
28 * the XML file that defines the appearance of the views.
29 */
30public abstract class ResourceCursorAdapter extends CursorAdapter {
31 private int mLayout;
32
33 private int mDropDownLayout;
34
35 private LayoutInflater mInflater;
36
37 /**
Dianne Hackbornc9189352010-12-15 14:57:25 -080038 * Constructor the enables auto-requery.
39 *
40 * @deprecated This option is discouraged, as it results in Cursor queries
41 * being performed on the application's UI thread and thus can cause poor
42 * responsiveness or even Application Not Responding errors. As an alternative,
43 * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}.
Jeff Hamiltonb721b472010-08-10 16:02:06 -050044 *
45 * @param context The context where the ListView associated with this adapter is running
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 * @param layout resource identifier of a layout file that defines the views
47 * for this list item. Unless you override them later, this will
48 * define both the item views and the drop down views.
49 */
Dianne Hackbornc9189352010-12-15 14:57:25 -080050 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 public ResourceCursorAdapter(Context context, int layout, Cursor c) {
52 super(context, c);
53 mLayout = mDropDownLayout = layout;
54 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
55 }
56
57 /**
Dianne Hackbornc9189352010-12-15 14:57:25 -080058 * Constructor with default behavior as per
59 * {@link CursorAdapter#CursorAdapter(Context, Cursor, boolean)}; it is recommended
60 * you not use this, but instead {@link #ResourceCursorAdapter(Context, int, Cursor, int)}.
61 * When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER}
62 * will always be set.
Jeff Hamiltonb721b472010-08-10 16:02:06 -050063 *
64 * @param context The context where the ListView associated with this adapter is running
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 * @param layout resource identifier of a layout file that defines the views
66 * for this list item. Unless you override them later, this will
67 * define both the item views and the drop down views.
68 * @param c The cursor from which to get the data.
69 * @param autoRequery If true the adapter will call requery() on the
70 * cursor whenever it changes so the most recent
Dianne Hackbornc9189352010-12-15 14:57:25 -080071 * data is always displayed. Using true here is discouraged.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 */
73 public ResourceCursorAdapter(Context context, int layout, Cursor c, boolean autoRequery) {
74 super(context, c, autoRequery);
75 mLayout = mDropDownLayout = layout;
76 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
77 }
78
79 /**
Dianne Hackbornc9189352010-12-15 14:57:25 -080080 * Standard constructor.
Jeff Hamiltonb721b472010-08-10 16:02:06 -050081 *
82 * @param context The context where the ListView associated with this adapter is running
Dianne Hackbornc9189352010-12-15 14:57:25 -080083 * @param layout Resource identifier of a layout file that defines the views
Jeff Hamiltonb721b472010-08-10 16:02:06 -050084 * for this list item. Unless you override them later, this will
85 * define both the item views and the drop down views.
86 * @param c The cursor from which to get the data.
Dianne Hackbornc9189352010-12-15 14:57:25 -080087 * @param flags Flags used to determine the behavior of the adapter,
88 * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}.
Jeff Hamiltonb721b472010-08-10 16:02:06 -050089 */
90 public ResourceCursorAdapter(Context context, int layout, Cursor c, int flags) {
91 super(context, c, flags);
92 mLayout = mDropDownLayout = layout;
93 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
94 }
95
96 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 * Inflates view(s) from the specified XML file.
98 *
99 * @see android.widget.CursorAdapter#newView(android.content.Context,
100 * android.database.Cursor, ViewGroup)
101 */
102 @Override
103 public View newView(Context context, Cursor cursor, ViewGroup parent) {
104 return mInflater.inflate(mLayout, parent, false);
105 }
106
107 @Override
108 public View newDropDownView(Context context, Cursor cursor, ViewGroup parent) {
109 return mInflater.inflate(mDropDownLayout, parent, false);
110 }
111
112 /**
113 * <p>Sets the layout resource of the item views.</p>
114 *
115 * @param layout the layout resources used to create item views
116 */
117 public void setViewResource(int layout) {
118 mLayout = layout;
119 }
120
121 /**
122 * <p>Sets the layout resource of the drop down views.</p>
123 *
124 * @param dropDownLayout the layout resources used to create drop down views
125 */
126 public void setDropDownViewResource(int dropDownLayout) {
127 mDropDownLayout = dropDownLayout;
128 }
129}