Instructions for using the multiplex list in iMAG

The reuse list (resue list) is another list that is different from the normal list in Aima. The reuse list is used to optimize performance. In the case of large data (thousands of items), it avoids excessive memory usage. resulting in a system crash. This is because a view (view) in a mobile application is an object that consumes a lot of system resources. Too many views (several thousands, and the memory size of the view depends on the area of ​​the view) may cause insufficient memory and crash. It also takes a long time to load so many views.

The corresponding solution to this is to use the reuse list. The principle of the reuse list is to only create a view object displayed on one screen. When the view is scrolled beyond the screen, it will be used for reuse, so it will only occupy the memory of one screen view. , which effectively solves the problem of crashes caused by insufficient memory, and has a fast loading speed because the number of views actually created is small.

The use of multiplexing lists needs to be set reuse="true". At the same time, there can only be one list in the content, and there cannot be multiple lists or other controls.

 

<content>
    <list id="resuelist" reuse="true">
        <item accessory="indicator">
            <label></label>
            <label style="color:gray"></label>
        </item>
    </list>
</content>

The items in the reuse list are very different from those in the normal list, because the items in the reuse list are not actual content, but UI templates, and the content of the items in the reuse list are dynamically created by Javascript scripts. A complete example of reuse list is as follows:

 

<?xml version="1.0" encoding="utf-8"?>
<imag>
    <script>
    <![CDATA[
        function initList() {
            var listJson = {items: []};
            for (var i = 0; i < 1000; i++) {
                var itemJson = {
                    template:0,
                    onclick:'alert("item' + i + '")',
                    widgets:{
                        title:{text:'title' + i},
                        subtitle:{text: 'subtitle' + i}
                    }
                }
                listJson.items.push(itemJson);
            }
            $('resuelist').update(listJson);
        }
         
        $page.onload = function() {
            initList();
        }
    ]]>   
    </script>
    <page>
        <title>
            <center>
                <label>reuse list</label>
            </center>
        </title>
        <content>
            <list id="resuelist" reuse="true">
                <item accessory="indicator">
                    <label reusekey="title"></label>
                    <label style="color:gray" reusekey="subtitle"></label>
                </item>
            </list>
        </content>
    </page>
</imag>




Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326776618&siteId=291194637