I have a ListActivity
. Each item in the ListView
contains a RatingBar
. When the user manipulates the RatingBar
, I want to update the corresponding data attached to the Adapter.
Unfortunately, inside my RatingBar
handler, I can't refer to the position variable. I understand why. I'm just having trouble finding a way around it.
How would I handle what I'm trying to do here?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// grab view
View v = convertView;
// set view layout
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.layout_rating_ratingbubble, null);
RatingBar r = (RatingBar)v.findViewById(R.id.rating_rating);
if (r != null) {
r.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// CANT REFER TO position HERE
m_items.get(position).setRating((int)rating);
}
});
}