I. Demand analysis
In the ordinary course of Android development. ListView, gridview adaptation of the writing is a very troublesome and very repetitive things, each time need to consider performance optimization, item writing, access to network images when the information confusion and other issues. So consider writing to implement a generic adapter that mainly considers the functionality:
(1) Adaptive item layout file, each use only need to pass in the layout ID number can be;
(2) Implement performance tuning for list lists. can re-use item, so that the loading speed of the list greatly increased;
(3) can get the picture loading list directly from the network, here consider only need to pass in the picture URL address, can realize the picture loading and the picture cache;
(4) easy to call.
This is my GitHub address for implementing a Universal adapter: Bash here
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvsvriywlszwk=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
The Generaadapter is the Universal adapter library, directly in eclipse to add a reference to (do not know to add the reference to Baidu), sample is to call this library file example.
Two. Calling methods
The invocation method is extremely simple, similar to the usual use of adapter usage. There are several main steps:
(1) Create a new item layout file, which is no different from your usual new layout.
(2) Create a new item class, here as the item item for the universal adapter, a Irem class is a piece of data
(3) define a list<item>, as the data for the universal adapter.
(4) New generaviewadapter<Item>, which will inherit convert on its own initiative Method
The above details can be seen Sample class Click to open link
Finally, the effect of the sample is this:
The above only requires 5-6 lines of code, but one such function.
GitHub Address: Bash here
Android Universal Adapter