Detailed explanation of using efficientadapter of Android listview

Detailed explanation of using efficientadapter of Android listview

Listview is a very common control in Android mobile application development. How to update and use it? In fact, the examples in the SDK are very complete and can meet most needs.

If you are just starting to learn listview, I suggest you just look at the official examples first, so that you will learn better writing methods and develop better habits.

Let's take efficientadapter as an example to see how listview is used on the official website:

Please pay special attention to the writing method of getview. You may have found some other examples on the Internet, but the writing method on the Internet is different from that on the official website. It is recommended that you use the example on the official website.

Brief description: to implement an efficient adapter, you need to do two things:

1. Reuse the convertview in getview () to avoid inflating the view when it is unnecessary.

2. Use viewholder mode to avoid calling findviewbyid() when it is unnecessary.

Incidentally, if you inherit listactivity and define listview in the layout XML, the ID of the listview must be "@ ID / Android: List". It is better to include a textview with ID "@ ID / Android: empty" for displaying the prompt text when there is no data in the listview. As follows:

XML code

Examples of efficientadapter on the official website are as follows:

Java code

Thank you for reading. I hope it can help you. Thank you for your support to this site. If you have any questions, please leave a message or go to the community of this site for communication and discussion. Let's make progress together!

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
分享
二维码
< <上一篇
下一篇>>