Android imitates iOS to realize three-level linkage selector

I believe that many children’s shoes who have used iOS will be impressed by the beautiful interface and user-friendliness of iOS. In fact, many effects on iOS can also be achieved on android. When doing projects today, we just need to use a three-dimensional similar to iOS. The cascade linkage selector is used to select the location (including province, city and district) for the user, which is hereby recorded for future reference.

 

First look at the renderings:



 

After reading the renderings, there is an urge to try it, and then start to realize the function. First of all, to analyze this effect, it can be divided into the following steps: 1. Obtain the data of the provinces and cities (if there is a server program, it can be obtained from the background, of course, for the sake of simplicity, the province_date.xml file is directly placed in the assets folder. , province_data.xml has been uploaded together with the source code ); 2. Make linkage control; 3. Add event response (here by callback).

 

The specific implementation methods are in the uploaded source code, but here is a point. Sometimes we do not necessarily need to be accurate to the district, maybe only the province and the city. So in order to improve the flexibility of the program, I put it in the code. Several fields for identification have been added, as follows:

 

public static final int STYLE_ONE=1;//First-level linkage
public static final int STYLE_TWO=2;//Secondary linkage
public static final int STYLE_THREE=3;//Three-level linkage

When three-level linkage is required, STYLE_THREE is passed in to the construction method, as shown in the above rendering. When only two-level linkage is required, STYLE_TWO is passed in, and the effect is shown in the following figure:



 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326495940&siteId=291194637