Usage analysis and understanding of baseadapter in Android

This paper analyzes the usage of baseadapter in Android. Share with you for your reference, as follows:

In a recent project, listview is used. The most important thing of listview is binding data, which is provided by the adapter. Here I rewrite the baseadapter class to implement my menuadapter. The code is as follows:

Methods to be overridden by baseadapter:

getCount(),getItem(int position),getItemId(int position),getView(int position,ViewGroup parent)

Process analysis:

When listview starts drawing, the system first calls the getcount () function to get the length of listview according to its return value, and then calls getview () to draw each line one by one according to this length. If your getcount () return value is 0, the list will not display the same return 1, but only one line. When the system displays the list, first instantiate an adapter (here the custom adapter will be instantiated). When the adaptation is completed manually, the data must be mapped manually, which requires overriding the getview () method. The system will call this method when drawing each row of the list. Getview () has three parameters, position indicates which line will be displayed, and covertview is the layout from the layout file. We use the layoutinflator method to define the defined item The XML file is extracted into a view instance for display. Then instantiate each component in the XML file (simple findviewbyid () method). In this way, the data can be mapped to each component. However, in order to respond to the click event, the button needs to add a click listener to it, so that the click event can be captured. So far, a custom listview has been completed. Now let's go back and review the process again. The system is going to draw the listview. First, it obtains the length of the list to be drawn, and then starts to draw the first row. How to draw it? Call the getview() function. In this function, first obtain a view (actually a ViewGroup), and then instance and set each component to display it. All right, I've finished drawing this line. Then draw the next line until it is finished.

More readers interested in Android related content can view the special topics of this site: summary of Android control usage, summary of Android view skills, summary of Android SQLite database skills, summary of Android JSON format data skills, summary of Android database operating skills, summary of Android file operating skills Summary of SD card operation methods for Android programming development, introduction and advanced tutorial for Android development, and summary of Android resource operation skills

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>