每次在适配器中调用getView()时,我都会尝试将数据写入文件。每次使用字符串值(listview的行数据)进行调用时,我都会附加到文件中。
我不会每次都打开文件,因为如果我这样做会严重影响性能。因此,我保持流打开,只在每次调用getView()时附加并写入新行。
当我在操作完成后稍后打开文件时,我看到我的文件中每行重复至少5-6次!该文件比它应该大得多。我在ListView上看到了正确的值。
我在getView()方法中的新线程中执行追加(我不使用AsyncTask。我只是说新的Thread(){run(){//我的操作}} .start()。
我使用的是Android 4.0。我认为getView()每行调用一次以上的问题已得到修复。还是有吗?
任何想法??
答案 0 :(得分:0)
请参阅Romain Guy在custom listview adapter getView method being called multiple times, and in no coherent order中的回复。引用他"This is not an issue, there is absolutely no guarantee on the order in which getView() will be called nor how many times."
您的ListView也可能将layout_width
设置为wrap_content
。再次,请参阅上面的链接以获取更多信息。