0

I'm developing a custom ListView, which uses a custom ArrayAdapter and custom elements.

Actually I'm displaying a list of tweets.

I want to display for every tweet the time elapsed from the creation, exactly like twitter.

I wrote a timer that calls a method on every list element. This method calculate the elapsed time and set it on a TextView on the element with setText().

Problem is that I can't get the list update. The values change only when I add a new element or manually scroll the list.

If you need code ask freely.

EDIT:

The answer of Nick Caballero is correct, but it wasn't working.

I have already tried that code. The problem was in the timer and in a try catch with a generic Exception.

The timer was trowing a CalledFromWrongThreadException. The solution was to use a runOnUiThread for its operations.

Marco Fedele
  • 2,090
  • 2
  • 25
  • 45

2 Answers2

0

You might want to try calling invalidate() on the control once its updated. Code would be helpful though.

sevensevens
  • 1,703
  • 16
  • 27
0

Calling notifyDataSetChanged does additional operations that are not necessary here. Updating the view with the time elapsed relative to the timestamp of the data does not imply a change in the data.

See https://stackoverflow.com/a/2679284/724068 for how to loop through the visible views in the list. You can then extract the view containing the time elapsed and update accordingly. Since you have to run this every so often to keep the UI up-to-date, you will have to use a Runnable, posting to the main Looper every second.

Also see https://stackoverflow.com/a/9987616/724068.

Community
  • 1
  • 1
Nick Caballero
  • 944
  • 1
  • 8
  • 19