首页 > 代码库 > Android之省市区三级联动

Android之省市区三级联动

最近项目要做一个电商APP,选择收货地址的三级联动滚动选择组件, 控件用起来非常简单 ,下面是它的运行效果:

       技术分享

布局

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:su="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    >

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:gravity="center"
        android:textColor="#FF0000"
        android:textSize="22sp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="选择地址"
        />
    <com.city.linkage.CityPickerView
        android:id="@+id/citypicker"
        android:layout_width="fill_parent"
        android:layout_height="156dp"
        android:layout_gravity="center"
        android:gravity="center"></com.city.linkage.CityPickerView>
    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="确定"
        />

</LinearLayout>

 

MainActivity.Java

public class MainActivity extends AppCompatActivity {

    private CityPickerView cityPicker;
    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cityPicker = (CityPickerView) findViewById(R.id.citypicker);
        tv=(TextView)findViewById(R.id.tv_name);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv.setText(cityPicker.getCity_string());
            }
        });
    }
}

由于代码太多,完整代码未给出,源码直接下载即可

 源码点击下载

Android之省市区三级联动