Skip to content

Commit 6584328

Browse files
author
Lyla
committed
Change FirebaseListAdapter to have a version of populateView that takes position as an argument
1 parent e5f7dec commit 6584328

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

library/src/main/java/com/firebase/ui/FirebaseListAdapter.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,46 @@ public long getItemId(int i) {
122122
}
123123

124124
@Override
125-
public View getView(int i, View view, ViewGroup viewGroup) {
125+
public View getView(int position, View view, ViewGroup viewGroup) {
126126
if (view == null) {
127127
view = mActivity.getLayoutInflater().inflate(mLayout, viewGroup, false);
128128
}
129129

130-
T model = mSnapshots.getItem(i).getValue(mModelClass);
130+
T model = mSnapshots.getItem(position).getValue(mModelClass);
131131

132132
// Call out to subclass to marshall this model into the provided view
133-
populateView(view, model);
133+
populateView(view, model, position);
134134
return view;
135135
}
136136

137137
/**
138138
* Each time the data at the given Firebase location changes, this method will be called for each item that needs
139-
* to be displayed. The arguments correspond to the mLayout and mModelClass given to the constructor of this class.
139+
* to be displayed. The first two arguments correspond to the mLayout and mModelClass given to the constructor of
140+
* this class. The third argument is the item's position in the list.
140141
* <p>
141142
* 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.
142145
*
143-
* @param v The view to populate
144-
* @param model The object containing the data used to populate the view
146+
147+
* @param position The position in the list of the view being populated
148+
*/
149+
protected void populateView(View v, T model, int position) {
150+
populateView(v, model);
151+
}
152+
153+
/**
154+
* This is a backwards compatible version of populateView.
155+
* <p>
156+
* You should implement either this method or the other {@link FirebaseListAdapter#populateView(View, Object, int)} method
157+
* but not both.
158+
*
159+
* @see FirebaseListAdapter#populateView(View, Object, int)
160+
*
161+
* @param v The view to populate
162+
* @param model The object containing the data used to populate the view
145163
*/
146-
protected abstract void populateView(View v, T model);
164+
protected void populateView(View v, T model) {
165+
166+
}
147167
}

0 commit comments

Comments
 (0)