1
1
package com .firebase .ui .database ;
2
2
3
3
import android .app .Activity ;
4
+ import android .content .Context ;
4
5
import android .support .annotation .LayoutRes ;
5
6
import android .util .Log ;
7
+ import android .view .LayoutInflater ;
6
8
import android .view .View ;
7
9
import android .view .ViewGroup ;
8
10
import android .widget .BaseAdapter ;
27
29
public abstract class FirebaseListAdapter <T > extends BaseAdapter implements FirebaseAdapter <T > {
28
30
private static final String TAG = "FirebaseListAdapter" ;
29
31
30
- protected final Activity mActivity ;
32
+ protected final Context mContext ;
31
33
protected final ObservableSnapshotArray <T > mSnapshots ;
32
34
protected final int mLayout ;
33
35
34
36
/**
35
- * @param activity The {@link Activity} containing the {@link ListView}
36
- * @param modelLayout This is the layout used to represent a single list item. You will be
37
- * responsible for populating an instance of the corresponding view with the
38
- * data from an instance of modelClass.
37
+ * @param context The {@link Activity} containing the {@link ListView}
39
38
* @param snapshots The data used to populate the adapter
39
+ * @param modelLayout This is the layout used to represent a single list item. You will be
40
+ * responsible for populating an instance of the corresponding view with the
41
+ * data from an instance of modelClass.
40
42
*/
41
- public FirebaseListAdapter (Activity activity ,
43
+ public FirebaseListAdapter (Context context ,
42
44
ObservableSnapshotArray <T > snapshots ,
43
45
@ LayoutRes int modelLayout ) {
44
- mActivity = activity ;
46
+ mContext = context ;
45
47
mSnapshots = snapshots ;
46
48
mLayout = modelLayout ;
47
49
@@ -54,23 +56,23 @@ public FirebaseListAdapter(Activity activity,
54
56
* @param query The Firebase location to watch for data changes. Can also be a slice of a
55
57
* location, using some combination of {@code limit()}, {@code startAt()}, and
56
58
* {@code endAt()}. <b>Note, this can also be a {@link DatabaseReference}.</b>
57
- * @see #FirebaseListAdapter(Activity , ObservableSnapshotArray, int)
59
+ * @see #FirebaseListAdapter(Context , ObservableSnapshotArray, int)
58
60
*/
59
- public FirebaseListAdapter (Activity activity ,
61
+ public FirebaseListAdapter (Context context ,
60
62
SnapshotParser <T > parser ,
61
63
@ LayoutRes int modelLayout ,
62
64
Query query ) {
63
- this (activity , new FirebaseArray <>(query , parser ), modelLayout );
65
+ this (context , new FirebaseArray <>(query , parser ), modelLayout );
64
66
}
65
67
66
68
/**
67
- * @see #FirebaseListAdapter(Activity , SnapshotParser, int, Query)
69
+ * @see #FirebaseListAdapter(Context , SnapshotParser, int, Query)
68
70
*/
69
- public FirebaseListAdapter (Activity activity ,
71
+ public FirebaseListAdapter (Context context ,
70
72
Class <T > modelClass ,
71
73
@ LayoutRes int modelLayout ,
72
74
Query query ) {
73
- this (activity , new ClassSnapshotParser <>(modelClass ), modelLayout , query );
75
+ this (context , new ClassSnapshotParser <>(modelClass ), modelLayout , query );
74
76
}
75
77
76
78
@ Override
@@ -126,7 +128,7 @@ public long getItemId(int i) {
126
128
@ Override
127
129
public View getView (int position , View view , ViewGroup viewGroup ) {
128
130
if (view == null ) {
129
- view = mActivity . getLayoutInflater ( ).inflate (mLayout , viewGroup , false );
131
+ view = LayoutInflater . from ( mContext ).inflate (mLayout , viewGroup , false );
130
132
}
131
133
132
134
T model = getItem (position );
0 commit comments