0

How to call notifyDataSetChanged() for only one element of gallery? Default call update evrything, which is quite resourse expencieve and unnecessary. I want solution, which works fro API 8.

Yarh
  • 4,459
  • 5
  • 45
  • 95

1 Answers1

1

To do that you need to find the row view that you want to refresh and make the refresh manually. Something like this:

private void updateSingleView(int i) {

    View viewToUpdate = listview.getChildAt(i - listview.getFirstVisiblePosition());
    //Do whatever update you need to do
    viewToUpdate.invalidate(); //Or postInvalidate() if you call it from a non Ui thread.
}

Found by this SO question.

Community
  • 1
  • 1
AggelosK
  • 4,313
  • 2
  • 32
  • 37
  • I have a problem. It does not work for galleryview. – Yarh Jul 25 '13 at 08:22
  • @user1551603 I suggest you move from `Gallery` to `ViewPager` since it is depracated from API 16 and up. You can use the android compatibility library to use the `ViewPager` in API 8 that you need. Link: http://developer.android.com/reference/android/widget/Gallery.html – AggelosK Jul 25 '13 at 08:50
  • i just dont want to rebuild quite big infrastacture:) – Yarh Jul 25 '13 at 08:57
  • 1
    @user1551603 You are right it requires quite a lot changes in your code but this way you futureproof your app and also I do not think what you ask is possible in Gallery (at least i do not know a way of achieving this to be frank:) ). – AggelosK Jul 25 '13 at 09:15