Android adapter BaseAdapter, androidbaseadapter

Source: Internet
Author: User

Android adapter BaseAdapter, androidbaseadapter

Public int getCount () data field size method public Object getItem (int arg0) returns the data of each Item according to public long getItemId (int arg0) returns the IDView getView (int arg0, view arg1, ViewGroup arg2) The most important thing is: redraw the View. The number of calls is determined by the first method. Finally, return the view. Note: Some controls must be set to no profit focus or click. The content written in these methods remains unchanged and has reference value. 2. Use ArrayList to implement List in the Data rewriting area. Encapsulate a data class and then load it into the List set. 3. Bind The data area to the view area setListAdapter (MyAdapter). Note: MyAdapter is a custom Adapter.

The three parameters of the getview method are as follows:

/*** @ Param position indicates that the position starts from 0. * @ param convertView indicates that the position starts from 0. The view * @ param parent to be displayed in the ListView is the parent form, that is, the content drawn by the * @ return usually return view, that is, the convertView * of ListView, is implemented here */abstract public View getView (int position, View convertView, viewGroup parent );
Call getView () to draw each row one by one. If your getCount () return value is 0, the list will not be displayed. Similarly, return 1 will show only one row. When the system displays the list, an adapter is first instantiated (the custom adapter will be instantiated here ). When manual adaptation is completed, data must be manually mapped, which requires the getView () method to be rewritten. This method is called when every row in the list is drawn. GetView () has three parameters. position indicates the row to be displayed, and covertView indicates the layout from inflate in the layout file. We use the LayoutInflater method to extract the defined item. xml file 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, to respond to a click event, you need to add a click listener for the button to capture the click event. So far, a custom listView is complete. Now let's look back at this process. The system wants to draw the ListView. He first obtains the length of the list to be drawn, and then begins to draw the first line. How can he draw it? Call the getView () function. In this function, first obtain a View (actually a ViewGroup), then instance and set each component to display it. Now, we have drawn this line. Then draw the next line until the painting is complete.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.