In the rewritten listview adapter, when printing a statement in the getview () method, the same position is printed multiple times. The modification method is as follows:
Change the height of the listview in the layout file to "fill_parent"
<Listview Android: Id = "@ + ID/dynamic_list" Android: layout_height = "fill_parent" Android: layout_width = "fill_parent" Android: scrollbars = "vertical" Android: layout_weight = "1" Android: drawselectid Top = "false" Android: fadingedgelength = "0dip" Android: divider = "@ null" Android: dividerheight = "0dip" Android: cachecolorhint = "#00000000" Android: Background = "@ color/listview_bg_color"/>
Reason, reference: http://blog.csdn.net/f8376904110/article/details/6460934
When using listview. Sometimes, when you customize the adapter, do you find that when printing logs in getview, you have repeatedly called it many times? Sometimes four times. Some are serious or even 10 times, when we move in listview. Each column is called many times, which greatly affects the efficiency! In fact, this is related to the listview mechanism on Android. Let me start with it:
In the layout, we only have one listview. That's good. When we set the height to wrap_content. Load several rows in the listview. Print the log in getview. Is the call repeated? That's all you need to do. Set the height to fill_parent. Are logs or repeated calls found at this time? Check whether the height of the previous level of listview is also set to fill_parent, if not. Change it. If yes... So I did not have to call it again! Because it has been tested several times!
If we have more than one listview. There may be many complicated and nice la S. The listview is located somewhere in the layout. Sometimes it's bad luck. You will find that you have called getview many times. I tested it. Up to 230 times... You can imagine. This speed is quite slow. In addition, each move is called so many times! When modifying the layout, consider the following two points: 1. Consider the demand layout and performance. 2. Consider which layout control affects listview!
If the performance is not significantly affected, the requirement must be in that layout. The layout is dominant. Check whether there are other methods to optimize the listview. The premise is that the layout cannot be adjusted at all. If it can be adjusted, the layout does not change much. The listview can be well optimized. Of course it is optimized! When we optimize it. First, check whether the controls that affect the re-painting of listview, for example. If it has controls above and below. And the height is wrap_content, so you need to set it to fill_parent or fixed height. In this way, the listview will not be repainted in height, which is the main point. Are there controls on the left and right? (generally, there are not so many controls when a mobile page uses list )? Yes, so we need to adjust the settings as well as the height. Make sure that the listview is fixed in that place. Otherwise, you will wait for him to call it again!
In fact, I have said so much. The most important thing is when we make the layout. You must skillfully use the attributes of each control and understand the principle of each control. In this way, we can integrate our uidesign well!