33
33
import android .view .ViewGroup ;
34
34
import android .widget .BaseAdapter ;
35
35
36
+ import com .firebase .client .DataSnapshot ;
36
37
import com .firebase .client .Firebase ;
37
38
import com .firebase .client .Query ;
38
39
48
49
* Firebase ref = new Firebase("https://<yourapp>.firebaseio.com");
49
50
* ListAdapter adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, mRef)
50
51
* {
51
- * protected void populateView(View view, ChatMessage chatMessage)
52
+ * protected void populateView(View view, ChatMessage chatMessage, int position )
52
53
* {
53
54
* ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
54
55
* ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
@@ -111,7 +112,14 @@ public int getCount() {
111
112
}
112
113
113
114
@ Override
114
- public T getItem (int i ) { return mSnapshots .getItem (i ).getValue (mModelClass ); }
115
+ public T getItem (int position ) {
116
+ if (mModelClass != DataSnapshot .class ) {
117
+ return mSnapshots .getItem (position ).getValue (mModelClass );
118
+ }
119
+ else {
120
+ return (T ) mSnapshots .getItem (position );
121
+ }
122
+ }
115
123
116
124
public Firebase getRef (int position ) { return mSnapshots .getItem (position ).getRef (); }
117
125
@@ -127,7 +135,7 @@ public View getView(int position, View view, ViewGroup viewGroup) {
127
135
view = mActivity .getLayoutInflater ().inflate (mLayout , viewGroup , false );
128
136
}
129
137
130
- T model = mSnapshots . getItem (position ). getValue ( mModelClass );
138
+ T model = getItem (position );
131
139
132
140
// Call out to subclass to marshall this model into the provided view
133
141
populateView (view , model , position );
@@ -140,30 +148,11 @@ public View getView(int position, View view, ViewGroup viewGroup) {
140
148
* this class. The third argument is the item's position in the list.
141
149
* <p>
142
150
* Your implementation should populate the view using the data contained in the model.
143
- * You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object)} method
144
- * but not both.
145
151
*
146
152
* @param v The view to populate
147
153
* @param model The object containing the data used to populate the view
148
154
* @param position The position in the list of the view being populated
149
155
*/
150
- protected void populateView (View v , T model , int position ) {
151
- populateView (v , model );
152
- }
156
+ abstract protected void populateView (View v , T model , int position );
153
157
154
- /**
155
- * This is a backwards compatible version of populateView.
156
- * <p>
157
- * You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object, int)} method
158
- * but not both.
159
- *
160
- * @see FirebaseListAdapter#populateView(View, Object, int)
161
- *
162
- * @param v The view to populate
163
- * @param model The object containing the data used to populate the view
164
- */
165
- @ Deprecated
166
- protected void populateView (View v , T model ) {
167
-
168
- }
169
158
}
0 commit comments