Question

I am trying to write data to a file each time getView() is called in a adapter. I append to the file every time the call is made with a string value (the row data of the listview).

I do not open the file every single time because the performance is affected severely if I do so. Hence, I keep the stream open and only append and write new line every time getView() is called.

When I open the file later after my operations are complete, I see each row duplicated in my file at least 5-6 times! The file is much larger than it should be. I see the correct values on my ListView though.

I perform appends in a new thread within the getView() method (I do not use a AsyncTask. I just say new Thread() { run() {//My operation}}.start().

I am using Android 4.0. I think the issue with getView() getting called more than once for every row has been fixed. Or has it?

Any ideas??

Was it helpful?

Solution

See Romain Guy's response in custom listview adapter getView method being called multiple times, and in no coherent order. To quote him "This is not an issue, there is absolutely no guarantee on the order in which getView() will be called nor how many times."

It may also be possible that your ListView has a layout_width set to wrap_content. Again, see the above link for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top