我现在有一个接口,接口中能获取很多网站数据,用一个ArrayList<HashMap<String,String>> 来存储这些需要显示在listview的数据。 现在实现的方案是:首先把接口中的数据全部读出来(貌似只能一次全部读出来),然后10条10条加载到listview中。
现在我在想,能不能通过这个接口一点一点的读?然后一点一点的放入ArrayList里面,比如读取接口中的10条数据,然后加载到listview中,感觉这样性能上会好很多。这样能实现吗?需要怎样才能实现呢?还是我想错了?请教各位了,谢谢!
If the interface has the function of pulling data in pages, then this problem does not exist.
Method 1: Write a server to process the data returned by the interface. That is, the paging logic that the client originally needs to process is done on the server, and the client only does brainless display.
Method 2: The client handles the paging logic (this is what you are doing now)
FaYi adds an intermediate layer, and pulling data may be slower.
Method 2 increases client resource consumption and performance loss.
Please compare the resources and time consumed by the two.
PS: Our interface usually adds page=num at the end to obtain paging data. Of course, there will be a flag in Json, for example: hasMore: "false/true". Based on this flag, it is decided whether there is more data.
This requires server-side database operation plus paging, 10 items per page. When the client requests, add the corresponding page number to get the corresponding paging data. For example, when the ListView is just loaded, the data on the first page is obtained, and when the ListView is pulled up to load more data, it is added to the next page.
But your scenario seems to have no paging. If you want to improve performance, process the data in paging on the client side. Convert the obtained data (such as Json string) into JsonArray, read 10 items each time, then parse and add them to the ArrayList, and then Display, this performance should be better.