SoulRayder SoulRayder - 1 year ago 67
Android Question

Triggering an image refresh within a particular row of ListView based on activity transistion event

I have a custom

within an Activity A, each row comprising of some ImageViews and TextViews.

First I navigate from Activity A to Activity B by using
method. I have succeeded in tracking the return from Activity B to Activity A through

Now, I want to trigger a image refresh (change of image based on some data values) for one of the ImageViews within a particular ListView row, when I return from another activity B, based on some data values set in that second activity.

Currently I figured out that I can pass the position value of the ListView row through the transition from A to B and back to A, but I am stuck on the further implementation.

How should I go about this? Most of the posts I see here talk about triggering image change from within an
for that ListView row. However, I need to do this based on the event of returning from Activity B to Activity A.

Any suggestions would be greatly appreciated. TIA.

Answer Source

The short answer is that you should never access a single ListView row and update it's View (There are ways to do it by keeping a reference to the displayed views, but you shouldn't).

What you should do is:

  1. When you get the result from Activity B, you set the data for the adapter in activity A for the row you want to update (or when you are doing onResume()).
  2. Call notifyDataSetChanged() for that adapter.
  3. The list will update and if that row is visible it will update accordingly.

There is no good reason not to follow this and update just one row (because if it takes too long to update the views, it means you are doing something wrong).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download