Android customizes the optimized layout of baseadapter

In the previous article, we introduced the general implementation layout of custom implementation of baseadapter. However, the previous chapter also said that the general implementation method will be inefficient and have great system overhead. Therefore, such implementation is to let beginners know that it can be used in this way. It is impossible to use that method in real projects, If you use the normal layout method when doing the project, I'm sure, but during the probation period, your boss will give you a plane ticket and leave. Well, don't gossip. This time, I'll explain the implementation of optimizing the layout. After reading the code, you'll think it's actually very simple.

MainActivity. java

MyAdapter. java

The above code implementation is very simple. It only uses a viewholder holding class to save the control ID in each layout. As we said in the second implementation of baseadapter in the previous article, although the number of parsing is minimized, findviewbyid is required every time, and the optimization here is just for that method, In this way, the number of parsing has been minimized and the number of findviewbyid has been minimized. However, for the adapter, there is no optimization, only better. That is to say, it is very convenient and efficient to use this method every time we write the listview layout in the future, Every time you write a listview to handle different data, you need to customize baseadapters. If one or two are OK, if your project has 20 listviews that handle different data, do you want to write 20 custom baseadapters? Therefore, in order to facilitate development, we can create a general baseadapter. How to create a general baseadapter will be introduced in the following learning notes.

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