List display method and device, computer equipment and computer readable medium
By creating a type cache pool and using the Viewholder mechanism, the problem of RecyclerView being unable to display multiple data structures and layout structures is solved, and efficient display and memory optimization of multiple data types are achieved.
Patent Information
- Application Number
- CN201910398910.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-14
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-03-21
AI Technical Summary
The existing RecyclerView in Android systems cannot display multiple types of data structures and multiple layout structures at the same time, and there are display limitations.
By creating a type cache pool, the relationship between multiple data structure types and their corresponding entries is cached, and the structure type and layout information of the data to be displayed are determined based on this relationship. Viewholder is used to render the data on the screen to implement multiple structure types. The data is displayed in the same RecyclerView.
It is possible to display multiple structural types of data in the same RecyclerView, avoiding memory waste, and reusing Viewholders when the list is pulled up and down, improving efficiency.
Smart Images

Figure CN111949841B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a list display method and device, computer equipment and computer-readable medium. Background Art
[0002] In the existing Android system API controls, RecyclerView is used to display data. However, due to the design limitations of RecyclerView itself, only the same type of data structure and the layout of a corresponding layout structure can be displayed, and the same RecyclerView cannot be used to display multiple types of data structures and multiple layout structures. Summary of the invention
[0003] The present invention aims to solve at least one of the technical problems existing in the prior art, and proposes a list display method and device, a computer device and a computer-readable medium.
[0004] In order to achieve the above object, the present invention provides a list display method, comprising:
[0005] Create a type cache pool, which caches: the correspondence between the structure types of multiple data and the entries corresponding to each structure type; each entry records its own layout information;
[0006] Get the structure type of each data in the list;
[0007] Display each data to be displayed in the to-be-displayed area of the list; wherein the step of displaying each data to be displayed includes:
[0008] Determine the entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of the multiple data cached in the type cache pool and the entries corresponding to the structure types;
[0009] Displaying the data to be displayed according to the layout information of the entry corresponding to the structure type of the data to be displayed;
[0010] The to-be-displayed area is the area where the list is to be displayed on the screen.
[0011] Optionally, when the area to be displayed is an initial part of the list, displaying each data to be displayed according to the layout information of the item corresponding to the structure type of each data to be displayed includes:
[0012] According to the entry corresponding to the structure type of the data to be displayed, create a Viewholder corresponding to the entry;
[0013] The Viewholder corresponding to the data to be displayed is called, so that the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed.
[0014] Optionally, the type cache pool further caches: a correspondence between entry type values and entries;
[0015] The calling of the Viewholder corresponding to the data to be displayed so that the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed also includes:
[0016] According to the correspondence between the entry type value and the entry, obtaining the entry type value corresponding to the structure type of the data to be displayed;
[0017] The entry type value corresponding to the structural type of the data to be displayed is passed to the Viewholder corresponding to the data to be displayed, so as to bind the Viewholder and the entry type value; wherein, when the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structural type of the data to be displayed, it is rendered according to the layout information of the entry corresponding to the entry type value bound to the Viewholder.
[0018] Optionally, the step of creating a type cache pool includes:
[0019] Create a first cache set and a second cache set;
[0020] In the first cache set, the structural types of multiple data and the entries corresponding to each structural type are registered and bound in turn; wherein, each time a structural type of data is registered and bound with a corresponding entry, the length of the first cache set is used as the entry type value of the entry, and the entry and its entry type value are bound and cached in the second cache set.
[0021] Optionally, the type cache pool also includes: a first member method and a second member method, wherein the first member method is: a method for obtaining a corresponding entry according to an entry type value;
[0022] The second member method is a method for obtaining an entry type value corresponding to a structure type of data to be displayed.
[0023] Optionally, the step of transmitting the entry type value corresponding to the structure type of the data to be displayed to the Viewholder corresponding to the data to be displayed further includes: storing the Viewholder and the entry type value corresponding to the Viewholder in a Recycler cache pool.
[0024] Optionally, when the area to be displayed is an area displayed on the screen when the list is dragged up or down,
[0025] The determining, according to the correspondence between the structural types of the plurality of data cached in the type cache pool and the entries corresponding to the structural types, the entry corresponding to the structural type of the data to be displayed includes:
[0026] Obtaining an entry type value corresponding to the structure type of the data to be displayed;
[0027] When there is an entry type value equal to the entry type value corresponding to the structure type of the data to be displayed in the Recycler cache pool, call the Viewholder corresponding to the entry type value, so that the Viewholder determines the entry corresponding to the structure type of the data to be displayed according to the entry type value; wherein the Viewholder called in this step is recorded as a reused Viewholder;
[0028] The displaying of the data to be displayed according to the layout information of the items corresponding to the structural type of each data to be displayed includes: the reused Viewholder renders the data to be displayed on the screen according to the layout information of the items determined by it.
[0029] Optionally, before the step of creating a type cache pool, the step also includes: customizing entries corresponding to structural types of multiple data.
[0030] Accordingly, the present invention also provides a list display device, comprising:
[0031] The buffer pool creation module is used to create a type buffer pool, in which the type buffer pool caches: the correspondence between the structure types of multiple data and the entries corresponding to each structure type; each entry records its own layout information;
[0032] The data type acquisition module is used to obtain the structure type of each data in the list;
[0033] An adapter, used for displaying each data to be displayed in the to-be-displayed area of the list; wherein, when displaying each data to be displayed, the adapter is specifically used for determining the entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of multiple data cached in the type cache pool and the entries corresponding to each structure type; and displaying the data to be displayed according to the layout information of the entry corresponding to the structure type of each data to be displayed;
[0034] The to-be-displayed area is the area where the list is to be displayed on the screen.
[0035] Optionally, the adapter comprises:
[0036] A Viewholder creating unit, configured to create a Viewholder corresponding to an entry according to an entry corresponding to a structure type of the data to be displayed, when the area to be displayed is an initial part of the list;
[0037] The rendering unit is used to call the Viewholder corresponding to the data to be displayed, so that the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed.
[0038] Optionally, the type cache pool further caches: a correspondence between entry type values and entries;
[0039] The adapter also includes:
[0040] A first type value obtaining unit, configured to obtain, when the to-be-displayed area is an initial part of the list, an entry type value corresponding to a structure type of each to-be-displayed data according to a correspondence between an entry type value and an entry;
[0041] A Viewholder binding unit, configured to transmit, when the area to be displayed is an initial part of the list, an entry type value corresponding to the structure type of the data to be displayed to a Viewholder corresponding to the data to be displayed, so as to bind the Viewholder to the entry type value;
[0042] When the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed, the rendering is performed according to the layout information of the entry corresponding to the entry type value bound to the Viewholder.
[0043] Optionally, the cache pool creation module includes:
[0044] A set creation unit, used to create a first cache set and a second cache set;
[0045] An entry binding unit registers and binds the structure types of multiple data with the entries corresponding to each structure type in the first cache set in turn; wherein, each time a structure type of data is registered and bound with a corresponding entry, the length of the first cache set is used as the entry type value of the entry, and the entry and its entry type value are bound and cached in the second cache set.
[0046] Optionally, the type cache pool further caches: a first member method and a second member method, wherein the first member method is: a method for obtaining a corresponding entry according to an entry type value;
[0047] The second member method is a method for obtaining an entry type value corresponding to a structure type of data to be displayed.
[0048] Optionally, the adapter further comprises:
[0049] A storage unit, configured to store the Viewholder and the entry type value corresponding to the Viewholder in a Recycler cache pool after the Viewholder binding unit binds the Viewholder to the entry type value;
[0050] A second type value acquisition unit, configured to acquire an entry type value corresponding to a structure type of the data to be displayed, when the area to be displayed is an area displayed on the screen when the list is dragged up or down;
[0051] A judgment unit is used to judge whether there is an entry type value in the Recycler cache pool that is equal to the entry type value obtained by the second type value acquisition unit when the area to be displayed is the area displayed on the screen when the list is pulled up or down; if so, the rendering unit calls the Viewholder corresponding to the entry type value.
[0052] Optionally, the list display device further includes: an entry customization module, which is used to customize entries corresponding to various data structure types.
[0053] Correspondingly, the present invention also provides a computer device, including a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the list display method as described above is implemented.
[0054] Correspondingly, the present invention also provides a computer-readable medium having a computer program stored thereon, and when the program is executed by a processor, the list display method as described above is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present invention but do not constitute a limitation of the present invention. In the accompanying drawings:
[0056] Figure 1 One of the flow charts of the list display method provided by the present invention;
[0057] Figure 2 A schematic diagram of the display process of each data to be displayed in step S4 of the present invention;
[0058] Figure 3 Flow chart 2 of the list display method provided by the present invention;
[0059] Figure 4 A flowchart of S42 in the step of displaying each to-be-displayed data in the initial part of the list according to the present invention;
[0060] Figure 5 A flow chart of displaying each data to be displayed in the area on the screen when the list is pulled up or down according to the present invention;
[0061] Figure 6 A structural schematic diagram of a list display device provided by the present invention;
[0062] Figure 7 A schematic diagram of the structure of the adapter. DETAILED DESCRIPTION
[0063] The specific implementation of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the present invention, and is not used to limit the present invention.
[0064] Figure 1 One of the flow charts of the list display method provided by the present invention is as follows: Figure 1 As shown, the list display method includes:
[0065] S1. Customize an adapter, which is used to process data of multiple structural types. The adapter inherits the Adapter of RecyclerView. In addition, in addition to the properties and methods in the Android native Adapter, the adapter also provides a method for adding the correspondence between the structural type of data and the entry to the type cache pool in step S2.
[0066] S2. Create a type cache pool, which caches: the correspondence between the structure types of multiple data and the items (Itemview) corresponding to each structure type. Each item records layout information, which includes information such as the ID, location and type of the layout file, and also provides a method for obtaining this information.
[0067] S3. Get the structure type of each data in the list.
[0068] Each data is data to be displayed on the screen and form an item of the list; for example, the data is data including a character string and a picture.
[0069] S4. Display each data to be displayed in the to-be-displayed area of the list.
[0070] Wherein, step S4 can be performed by the adapter in step S1. The area to be displayed is the area of the list to be displayed on the screen. For example, when the list is not pulled down, the area to be displayed of the list is: the part that can be displayed on the screen starting from the top of the list (hereinafter referred to as the initial part of the list). The data to be displayed is: the data to be displayed on the screen.
[0071] Figure 2 FIG. 4 is a schematic diagram of the display process of each data to be displayed in step S4 of the present invention, as shown in FIG. Figure 2 As shown, the steps for displaying each data to be displayed include:
[0072] S41 . Determine an entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of the various data cached in the type cache pool and the entries corresponding to the structure types.
[0073] S42. Display the data to be displayed according to the layout information of the entries corresponding to the structural type of the data to be displayed. In the present invention, the structural types of various data are first bound and stored with their corresponding entries through a cache mechanism in a type cache pool; when displaying the list, the layout information of the entries corresponding to the structural type of the data to be displayed is obtained according to the corresponding relationship in the cache, so as to display it according to the corresponding layout information. Therefore, the present invention can use the same RecyclerView control to display a list of data of multiple structural types. In addition, in the type cache pool, data and entries of the same structural type only need to be created once, so that memory waste can be avoided.
[0074] Figure 3 The second flowchart of the list display method provided by the present invention is as follows: Figure 3 As shown, the list display method includes:
[0075] S0. Customize multiple entries, each of which corresponds to a variety of data structure types.
[0076] Each entry is a custom class with generics. The generics in the custom class correspond to the structure type or data source of the data to be bound. The custom entry records the layout information of the entry through attributes, and also provides a method for obtaining the layout information externally. The layout information includes the ID, location, and type of the layout file (for example, each sub-control corresponding to text, pictures, etc. in the entry).
[0077] S1. Customize an adapter, which is used to process data of various structural types. The adapter inherits the Adapter of RecyclerView. In addition, in addition to the properties and methods in the Android native Adapter, the adapter also declares the method of registering the correspondence between the structure type and the entry of the binding data in the type cache pool; and the method of creating and binding Viewholder. The method of binding Viewholder is the method of obtaining the entry corresponding to the corresponding entry type value from the type cache pool.
[0078] In actual applications, you can also add some event association extension methods to the custom adapter and custom items to enhance scalability. For example, you can add pull-up and pull-down refresh related codes in the custom adapter, and you can also customize the various animation effects involved. For example, through the custom items, you can associate some click and touch events (such as a single item left swipe to delete or drag effects) for expansion.
[0079] S2. Create a type cache pool. The type cache pool caches: the correspondence between the structure types of multiple data and the entries corresponding to each structure type, and also caches the correspondence between the entry type value and the entry.
[0080] Specifically, step S2 includes steps S21 and S22:
[0081] S21: Create a first cache set and a second cache set.
[0082] S22. Register and bind the structure types of multiple data and the entries corresponding to each structure type in the first cache set in turn (i.e., add the correspondence between the structure type of each data and its corresponding entry to the first cache set). Each time a structure type of data is registered and bound to a corresponding entry, the length (size) of the first cache set will be incremented by 1. At this time, the length of the first cache set is used as the entry type value of the entry, and the entry and its entry type value are bound and cached in the second cache set. The first cache set can use the ArrayMap collection in the Android system, and the second cache set can use the SparseArray collection that saves more memory.
[0083] When each list is displayed, a type cache pool may be created; and when each list is displayed, data of a certain structure type to be displayed in the entire list may be pre-acquired from the server.
[0084] In addition, the first member method (getitemview()) and the second member method (getitemviewtype()) are provided in the type cache pool. The first member method is a method for obtaining a corresponding entry according to an entry type value; the second member method is a method for obtaining an entry type value corresponding to the structural type of the data to be displayed. In the second member method, the data is taken as an incoming object, and the object.getClass() method of the incoming object object is called to obtain the class type (i.e., the structural type of the data); the corresponding custom entry is obtained in the first cache set, and then the entry type value is obtained in the second cache set according to the entry. In the first member method, the previously cached entry is obtained from the second cache set according to the incoming parameter (i.e., the entry type value).
[0085] In addition, the type cache pool also provides a method that needs to be called in the adapter: registering the corresponding relationship between the structure type of the bound data and the entry. In this method, the structure type of the data is bound to the corresponding entry and stored in the first cache set. At the same time, the length of the first cache set and the corresponding entry are cached in the second cache set, thereby completing the cache process. While completing the cache process, a method for setting the maximum number of reused entries is also required. In this method, the maximum number of entry type values cached in the Recycler cache pool is set.
[0086] S3. Obtain the structure type of each data in the list. For example, when the data includes a title and a picture, the data is of the first structure type; when the data includes a title, multiple pictures and time, the data is of the second structure type, and so on.
[0087] S4. Display each data to be displayed in the to-be-displayed area of the list.
[0088] Among them, the length of the list can be smaller than the screen length of the display device, so that it can be fully displayed on one screen. Of course, the length of the list can also be greater than the length of the screen, so that the initial part of the list is displayed first; when pulling up and down, the data structure newly added to the screen is displayed.
[0089] The steps for displaying each data to be displayed include:
[0090] S41 . Determine an entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of the various data cached in the type cache pool and the entries corresponding to the structure types.
[0091] S42: Display the data to be displayed according to the layout information of the entry corresponding to the structure type of the data to be displayed.
[0092] Among them, Viewholder can be used to render each data on the screen, and when the area to be displayed is the initial part of the list, a new Viewholder corresponding to the data to be displayed can be created when each data to be displayed; when the area to be displayed is the area displayed on the screen when the list is pulled up and down, the Viewholder used in the display process of the initial part of the list can be reused when each data to be displayed.
[0093] Figure 4 This is a flowchart of S42 in the step of displaying each data to be displayed in the initial part of the list of the present invention, as shown in FIG. Figure 4 As shown, when the area to be displayed is the initial part of the list, step S42 includes:
[0094] S421, according to the correspondence between the item type value and the item, obtain the item type value corresponding to the structure type of the data to be displayed. Specifically, when the data to be displayed is the data in the initial part of the list, steps S41 and S421 can call the getitemviewtype() method, first obtain the item corresponding to the structure type of each data according to the correspondence of the first cache set, and then obtain the item type value according to the correspondence of the second cache set.
[0095] S422. Create a Viewholder corresponding to the entry according to the structure type of the data to be displayed.
[0096] S423: The entry type value corresponding to the structure type of the data to be displayed is transmitted to the Viewholder corresponding to the data to be displayed, so as to bind the Viewholder and the entry type value.
[0097] S424. Store the ViewHolder and its corresponding entry type value into the system's Recycler cache pool.
[0098] S425 . Call the Viewholder corresponding to the data to be displayed, so that the Viewholder renders the data to be displayed on the screen according to the layout information of the item corresponding to the structure type of the data to be displayed.
[0099] Among them, when Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed, it renders according to the layout information of the entry corresponding to the entry type value bound to Viewholder.
[0100] Among them, the entry corresponding to each entry type value can be obtained by calling the first member method, and the first member method determines the entry corresponding to the entry type value bound to the Viewholder in the Recycler cache pool according to the correspondence between the entries cached in the second cache set and the entry type values.
[0101] It should be noted that step S424 and step S425 may not be continuous. After step S424 is completed, the system may perform other processes and then proceed to step S425.
[0102] In addition, the layout information in the entry also includes height information; in the actual display process, after obtaining the structure type of the M data in the list, the entry corresponding to each data is determined in turn; each time an entry corresponding to a data is determined, it is judged whether the data to be displayed exceeds the screen based on the height information in the entry and the screen size. If not, a new Viewholder is created, and the Viewholder is used to render the data to be displayed on the screen; when the sum of the heights of the entries corresponding to the current N data reaches the screen height, it is considered that the initial part of the list can display the first N data; then when displaying the data after the Nth data, the created Viewholder is reused to display the data to be displayed.
[0103] Figure 5 This is a flow chart of displaying each data to be displayed in the area on the screen when the list is pulled up or down in the present invention, such as Figure 5 As shown, when the area to be displayed is the area displayed on the screen when the list is dragged up and down, the display step for each data to be displayed includes step S41 and step S42.
[0104] Wherein, step S41 includes:
[0105] S411. Obtain an entry type value corresponding to the structure type of the data to be displayed.
[0106] For example, the initial part of the list can display N data. When the scrolling occurs, that is, when the N+ith data is to be displayed on the screen, the entry type value corresponding to the data type of the N+ith data is obtained. i is an integer greater than 0, and N+i is not greater than the total number of data in the list. In step S411, the Adapter can inherit an original method of obtaining the entry type value in the system by using the callback method, and this method can directly obtain the entry type value corresponding to the N+ith data.
[0107] S412. Determine whether there is an entry type value in the Recycler cache pool that is equal to the entry type value obtained in step S411; if so, proceed to step S413; otherwise, proceed to step S414.
[0108] S413: Call the Viewholder corresponding to the entry type value equal to the entry type value obtained in step S411, so that the Viewholder determines the entry corresponding to the structure type of the data to be displayed according to the entry type value. The Viewholder called in step S413 is recorded as a reused Viewholder.
[0109] Exemplarily, if the entry type value obtained in step S411 is equal to the entry type value of the third entry in the initial part of the list, then the Viewholder corresponding to the entry type value of the third entry in the initial part of the list is called.
[0110] S414: Create a new Viewholder, pass the entry type value obtained in step S411 to the newly created Viewholder, and add the Viewholder and its corresponding entry type value to the system's Recycler cache pool.
[0111] After this, the system can proceed to other processes and then continue to S415:
[0112] S415. Call a Viewholder (referred to as a reused Viewholder) corresponding to an entry type value equal to the entry type value obtained in step S411 from the Recycler cache pool, so that the Viewholder determines the entry corresponding to the structure type of the data to be displayed according to the entry type value.
[0113] After step S41 is completed, step S42 is performed to display the data to be displayed according to the layout information of the item corresponding to the structure type of the data to be displayed. The step S42 specifically includes: S42a, the reused Viewholder renders the data to be displayed on the screen according to the layout information of the item determined by it.
[0114] That is to say, when rendering, the data structure newly added to the screen can use the Viewholder corresponding to the previous initial part of the data for rendering, thereby realizing the reuse of Viewholder.
[0115] In the list display method provided by the present invention, data and entries of various structural types are first stored through a cache mechanism in a type cache pool; when displaying the list, the layout information of the entries corresponding to the structural type of the data to be displayed is obtained according to the corresponding relationship in the cache, so as to display it according to the corresponding layout information. Therefore, the present invention can use the same RecyclerView control to display a list of data of multiple structural types. At the same time, in the type cache pool, data and entries of the same structural type only need to be created once, so memory waste can be avoided. In addition, when the list is pulled up and down, if the entry type value corresponding to the data newly added to the screen is the same as the entry type value corresponding to a certain data in the initial part of the list, the Viewholder used to display the initial part of the list can be called without recreating the Viewholder, thereby realizing the reuse of the Viewholder.
[0116] Figure 6 A structural diagram of a list display device provided by the present invention, such as Figure 6 As shown, the list display device includes: an adapter 10, a buffer pool creation module 20 and a data type acquisition module 30.
[0117] The adapter 10 is used to process data of various structural types.
[0118] The buffer pool creation module 20 is used to create a type buffer pool, in which the type buffer pool caches: the correspondence between the structure types of multiple data and the entries corresponding to each structure type; and each entry records its own layout information.
[0119] The data type acquisition module 30 is used to acquire the structure type of each data in the list.
[0120] The adapter 10 is specifically used to display each data to be displayed in the area to be displayed of the list; wherein, when displaying each data to be displayed, the adapter is specifically used to determine the item corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of multiple data cached in the type cache pool and the items corresponding to each structure type; and display the data to be displayed according to the layout information of the item corresponding to the structure type of each data to be displayed. The area to be displayed is the area of the list to be displayed on the screen.
[0121] Furthermore, the list display device also includes: an item customization module 40, which is used to customize items corresponding to various data structure types.
[0122] Optionally, the type cache pool also caches: a correspondence between the entry type value and each entry.
[0123] The cache pool creation module 20 includes: a set creation unit 21 and an entry binding unit 22. The set creation unit 21 is used to create a first cache set and a second cache set. The entry binding unit 22 is used to register and bind the structure types of multiple data with the entries corresponding to each structure type in the first cache set in sequence; wherein, each time a structure type of data is registered and bound with a corresponding entry, the length of the first cache set is used as the entry type value of the entry, and the entry and its entry type value are bound and cached in the second cache set.
[0124] In addition, the type cache pool also caches: a first member method and a second member method. The first member method is a method for obtaining a corresponding entry according to an entry type value; the second member method is a method for obtaining an entry type value corresponding to the structure type of the data to be displayed.
[0125] Figure 7 is a schematic diagram of the structure of the adapter, such as Figure 7 As shown, the adapter 10 includes: a Viewholder creation unit 11, a first type value acquisition unit 12, a Viewholder binding unit 13, a storage unit 14, a rendering unit 15, a second type value acquisition unit 17 and a judgment unit 16.
[0126] The Viewholder creation unit 11 is used to create a Viewholder corresponding to an entry according to an entry corresponding to a structure type of the data to be displayed when the area to be displayed is an initial part of the list.
[0127] The first type value obtaining unit 12 is used to obtain the entry type value corresponding to the structure type of each to-be-displayed data according to the correspondence between the entry type value and the entry when the to-be-displayed area is the initial part of the list.
[0128] The Viewholder binding unit 13 is used to transmit the item type value corresponding to the structure type of the data to be displayed to the Viewholder corresponding to the data to be displayed, so as to bind the Viewholder with the item type value, when the area to be displayed is the initial part of the list.
[0129] The storage unit 14 is used to store the Viewholder and its corresponding entry type value in the Recycler cache pool after the Viewholder binding unit binds the Viewholder to the entry type value.
[0130] The rendering unit 15 is used to call the Viewholder corresponding to the data to be displayed, so that the Viewholder renders the data to be displayed on the screen according to the layout information of the item corresponding to the structure type of the data to be displayed. When the Viewholder renders the data to be displayed on the screen according to the layout information of the item corresponding to the structure type of the data to be displayed, the rendering is performed according to the layout information of the item corresponding to the item type value bound to the Viewholder.
[0131] The second type value acquisition unit 17 is used to obtain the entry type value corresponding to the structural type of the data to be displayed when the area to be displayed is the area displayed on the screen when the list is dragged up and down; that is, when the list is dragged up and down, the entry type value corresponding to the structural type of the data added to the screen is obtained.
[0132] The judgment unit 16 is used to judge whether there is an entry type value in the Recycler cache that is equal to the entry type value obtained by the second type value acquisition unit 17 when the area to be displayed is the area displayed on the screen when the list is pulled up or down; if so, the rendering unit 15 calls the Viewholder corresponding to the entry type value.
[0133] The process and principle of list display have been introduced above, so I will not repeat them here.
[0134] The present invention also provides a computer device, including a memory and a processor, and when a computer program is executed by the processor, the list display method as described above is implemented.
[0135] The present invention also provides a computer-readable medium having a computer program stored thereon, wherein the program implements the list display method as described above when executed by a processor.
[0136] The above-mentioned memory and the computer storage medium include but are not limited to the following readable media: such as random access memory (RAM), read-only memory (ROM), non-volatile random access memory (NVRAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable PROM (EEPROM), flash memory, magnetic or optical data storage, registers, disks or tapes, optical storage media such as compact disks (CD) or DVDs (digital versatile disks), and other non-transitory media. Examples of processors include but are not limited to general-purpose processors, central processing units (CPUs), microprocessors, digital signal processors (DSPs), controllers, microcontrollers, state machines, etc.
[0137] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A list display method, characterized in that: include: Create a type cache pool, which caches: the correspondence between the structure types of multiple data and the entries corresponding to each structure type, and the correspondence between the entry type value and the entry; each entry records its own layout information; Get the structure type of each data in the list; Display each data to be displayed in the to-be-displayed area of the list; wherein the step of displaying each data to be displayed includes: Determine the entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of the multiple data cached in the type cache pool and the entries corresponding to the structure types; Displaying the data to be displayed according to the layout information of the entry corresponding to the structure type of the data to be displayed; The to-be-displayed area is the area on the screen where the list is to be displayed; Wherein, when the area to be displayed is the initial part of the list, displaying each data to be displayed according to the layout information of the item corresponding to the structure type of each data to be displayed includes: According to the entry corresponding to the structure type of the data to be displayed, create a Viewholder corresponding to the entry; Calling the Viewholder corresponding to the data to be displayed, so that the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed; When the area to be displayed is an area displayed on the screen when the list is dragged up or down, determining the entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of the multiple data cached in the type cache pool and the entries corresponding to the structure types includes: Obtaining an entry type value corresponding to the structure type of the data to be displayed; When there is an entry type value equal to the entry type value corresponding to the structure type of the data to be displayed in the Recycler cache pool, call the Viewholder corresponding to the entry type value, so that the Viewholder determines the entry corresponding to the structure type of the data to be displayed according to the entry type value; wherein the Viewholder called in this step is recorded as a reused Viewholder; The displaying of the data to be displayed according to the layout information of the items corresponding to the structural type of each data to be displayed includes: the reused Viewholder renders the data to be displayed on the screen according to the layout information of the items determined by it.
2. The list display method according to claim 1, characterized in that: The calling of the Viewholder corresponding to the data to be displayed so that the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed also includes: According to the correspondence between the entry type value and the entry, obtaining the entry type value corresponding to the structure type of the data to be displayed; The entry type value corresponding to the structural type of the data to be displayed is passed to the Viewholder corresponding to the data to be displayed, so as to bind the Viewholder and the entry type value; wherein, when the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structural type of the data to be displayed, it is rendered according to the layout information of the entry corresponding to the entry type value bound to the Viewholder.
3. The list display method according to claim 2, characterized in that: The steps of creating a type buffer pool include: Creating a first cache set and a second cache set; In the first cache set, the structural types of multiple data and the entries corresponding to each structural type are registered and bound in turn; wherein, each time a structural type of data is registered and bound with a corresponding entry, the length of the first cache set is used as the entry type value of the entry, and the entry and its entry type value are bound and cached in the second cache set.
4. The list display method according to claim 2, characterized in that: The type cache pool also includes: a first member method and a second member method, wherein the first member method is: a method for obtaining a corresponding entry according to an entry type value; The second member method is a method for obtaining an entry type value corresponding to a structure type of data to be displayed.
5. The list display method according to claim 2, characterized in that: The step of transmitting the entry type value corresponding to the structure type of the data to be displayed to the Viewholder corresponding to the data to be displayed further includes: storing the Viewholder and the entry type value corresponding to the Viewholder in a Recycler cache pool.
6. The list display method according to claim 1, characterized in that: Before the step of creating a type cache pool, the step also includes: customizing entries corresponding to the structural types of multiple data.
7. A list display device, characterized in that: include: A cache pool creation module is used to create a type cache pool, in which: the correspondence between the structure types of multiple data and the entries corresponding to each structure type, and the correspondence between the entry type value and the entry; each entry records its own layout information; The data type acquisition module is used to obtain the structure type of each data in the list; An adapter, used for displaying each data to be displayed in the to-be-displayed area of the list; wherein, when displaying each data to be displayed, the adapter is specifically used for determining the entry corresponding to the structure type of the data to be displayed according to the correspondence between the structure types of multiple data cached in the type cache pool and the entries corresponding to each structure type; and displaying the data to be displayed according to the layout information of the entry corresponding to the structure type of each data to be displayed; The to-be-displayed area is the area on the screen where the list is to be displayed; The adapter comprises: A Viewholder creating unit, configured to create a Viewholder corresponding to an entry according to an entry corresponding to a structure type of the data to be displayed, when the area to be displayed is an initial part of the list; A rendering unit, used for calling a Viewholder corresponding to the data to be displayed, so that the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed; A second type value acquisition unit, configured to acquire an entry type value corresponding to a structure type of the data to be displayed, when the area to be displayed is an area displayed on the screen when the list is dragged up or down; A judgment unit is used to judge whether there is an entry type value in the Recycler cache pool that is equal to the entry type value obtained by the second type value acquisition unit when the area to be displayed is the area displayed on the screen when the list is pulled up or down; if so, the rendering unit calls the Viewholder corresponding to the entry type value.
8. The list display device according to claim 7, characterized in that: The adapter also includes: A first type value obtaining unit, configured to obtain, when the to-be-displayed area is an initial part of the list, an entry type value corresponding to a structure type of each to-be-displayed data according to a correspondence between an entry type value and an entry; A Viewholder binding unit, configured to transmit, when the area to be displayed is an initial part of the list, an entry type value corresponding to the structure type of the data to be displayed to a Viewholder corresponding to the data to be displayed, so as to bind the Viewholder to the entry type value; When the Viewholder renders the data to be displayed on the screen according to the layout information of the entry corresponding to the structure type of the data to be displayed, the rendering is performed according to the layout information of the entry corresponding to the entry type value bound to the Viewholder.
9. The list display device according to claim 8, characterized in that: The buffer pool creation module includes: A set creation unit, used to create a first cache set and a second cache set; An entry binding unit registers and binds the structure types of multiple data with the entries corresponding to each structure type in the first cache set in turn; wherein, each time a structure type of data is registered and bound with a corresponding entry, the length of the first cache set is used as the entry type value of the entry, and the entry and its entry type value are bound and cached in the second cache set.
10. The list display device according to claim 8, characterized in that: The type cache pool also caches: a first member method and a second member method, wherein the first member method is a method for obtaining a corresponding entry according to an entry type value; The second member method is a method for obtaining an entry type value corresponding to a structure type of data to be displayed.
11. The list display device according to claim 8, characterized in that: The adapter also includes: The storage unit is used to store the Viewholder and its corresponding entry type value in the Recycler cache pool after the Viewholder binding unit binds the Viewholder to the entry type value.
12. The list display device according to claim 7, characterized in that: The list display device further comprises: an item customization module, which is used to customize items corresponding to various data structure types.
13. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the computer program is executed by the processor, the list display method according to any one of claims 1 to 6 is implemented.
14. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the list display method according to any one of claims 1 to 6 is implemented.
