Question

Am using AndroidAnnotations 2.7.1 and have been using it successfully throughout my application. However, I recently stumbled upon some issues related to adapters and custom views with @EViewGroup. Followed the recipe described in the cookbook.

I have two different adapters and two different custom views.

In both adapters the wrong ImageView in a row of the ListView is updated with the image loaded by the library Android Universal Image Loader. And in one adapter multiple checkboxes are checked by only clicking one.

ShowView and ShowsAdapter <-- Wrong ImageView and Checkbox updated in row of ListView

ShowScheduleView and ScheduleAdapter <-- Wrong ImageView in row of ListView

I know the getView() is called multiple times to determine the height of each row.

Have also tried with ViewHolders and .resetViewBeforeLoading() in the UIL options but to no avail.

What might cause this behaviour?

Thank you in advance!

Était-ce utile?

La solution

As the views are recycled by the adapter, you probably keep an old state from a previous display of that view.

Check how you bind the data to your custom view, by having in mind that all previously bound data can be kept if they're not reset.

For instance the following data bind method in a custom view can lead to the same problem :

public void bind(Data data) {
   if (data.foo) {
      textView.setColor(Color.WHITE);
   }
   (...)
}

If the view is recycled and previously data.foo was true, if now data.foo is false, the textView will keep its color to white. The correct way is so :

public void bind(Data data) {
   if (data.foo) {
      textView.setColor(Color.WHITE);
   } else {
      textView.setColor(<inital color>);
   }
   (...)
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top