android - 非常不错的 城市省份的选择组件: citypicker

访问量: 63

参考:https://github.com/crazyandcoder/citypicker

用法:

1.  修改根目录下的build.gradle, 增加:

   dependencies: { 
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
   }

2. 修改  app/build.gradle, 增加: 

dependencies: { 
    compile project(':citypickerview')
}

3. 把 上面github 源代码中的 citypickerview 目录整个 copy到根目录下

4. settings.gradle文件:

include ':app', ':citypickerview'

5. 找到某个Activity (例如MainActivity.java)  ,  在对应的xml中,增加:

<TextView    android:id="@+id/province_and_city">

6. 点击该按钮之后,会弹出这个View: 

        provinceAndCity = (TextView)findViewById(R.id.province_and_city);
        //城市滚轮选择器
        provinceAndCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CityPickerView cityPicker = new CityPickerView.Builder(UserEditActivity.this).textSize(20)
                        .titleTextColor("#000000")
                        .backgroundPop(0xa0000000)
                        .province("江苏省")
                        .city("南京市")
                        .district("秦淮区")
                        .textColor(Color.parseColor("#000000"))
                        .provinceCyclic(true)
                        .cityCyclic(false)
                        .districtCyclic(false)
                        .visibleItemsCount(7)
                        .itemPadding(10)
                        .build();
                cityPicker.show();
                cityPicker.setOnCityItemClickListener(new CityPickerView.OnCityItemClickListener() {
                    @Override
                    public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                        //返回结果
                        Log.d(TAG, "== 所选城市:" + province.getName() + "  " + city.getName() + "   " + district.getName());
                    }

                    @Override
                    public void onCancel() {

                    }
                });
            }
        });

订阅/RSS Feed

Subscribe

分类/category