Android listview custom adapter implements QQ like interface

There are some simple adapters in PS: listview, such as: simpleadapter: construction method simpleadapter (context, context, list < map < string,? > > data, rstring [] from, int [] to), but this adapter is too monotonous and often can not achieve the desired effect. If you want to do whatever you want, you use baseadapter and custom adapter.

As shown in the figure:

1. First write the layout file

activity_ layout.xml

There is no item style: itemstyle_ You can find any picture in layout.xml.

2. Create adapter myadapter.java (optimized)

To be clear, there are optimization methods in the adaptation. If they are not optimized, they can be loaded sometimes, but sometimes they will be loaded disorderly. If they are not called once, they will waste more time creating a view object, such as:

After optimization (added viewholder)

3. Load the listview control in mainactivity. Java and assign a value to the list.

It's done.

Summary: benefits of adding viewholder to code optimization: (official translation)

Reuse the cache convertview and pass it to the getview() method to avoid filling unnecessary views. Use the viewholder mode to avoid unnecessary calls to findviewbyid(): too many findviewbyids will also affect performance. The viewholder mode stores a data structure in the tag of the view returned through the getview() method, This data structure contains a reference to the view we want to bind data to, so as to avoid calling findviewbyid () every time getview () is called.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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