I. Demand analysis
In the normal Android development process, the ListView, GridView adaptation of the writing is a very cumbersome and very repetitive things, every time need to consider performance optimization, item writing, get network pictures when the information of the confusion and so on, so consider writing to implement a generic adapter, The main features to consider:
(1) Adaptive item layout file, each use only need to pass in the layout ID number;
(2) To achieve the performance tuning of list lists, the ability to reuse item, so that the loading speed of the list greatly improved;
(3) can get the picture loading list directly from the network, here consider only need to pass in the image URL address, namely 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
Where Generaadapter is the Universal adapter library, directly add a reference to eclipse (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, with the following 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>, it will automatically inherit convert Method
For more details, please refer to Sample class Click to open link
The effect of the final example is this:
This is a feature that requires only 5-6 lines of code.
GitHub Address: Bash here
Android Universal Adapter