獲取城市列表
阿新 • • 發佈:2017-09-08
save als ted blog app pub add 獲取 .sh
依賴
dependencies { ... compile ‘liji.library.dev:citypickerview:0.7.0‘ }
主
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button go= (Button) findViewById(R.id.go); final TextView tvResult = (TextView) findViewById(R.id.tv_result); go.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CityPicker cityPicker = new CityPicker.Builder(MainActivity.this).textSize(20) .textColor(Color.parseColor("#000000")) .provinceCyclic(true) .cityCyclic(false) .districtCyclic(false) .visibleItemsCount(7) .itemPadding(10) .build(); cityPicker.show(); cityPicker.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener() { @Override public void onSelected(String... citySelected) { tvResult.setText("選擇結果:\n省:" + citySelected[0] + "\n市:" + citySelected[1] + "\n區:" + citySelected[2] + "\n郵編:" + citySelected[3]); } }); } }); }}
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/go" android:layout_width="match_parent" android:layout_height="60dp" android:text="選擇省市區" /> <TextView android:id="@+id/tv_result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/go" android:layout_marginTop="10dp" android:text="選擇結果:" android:textSize="20sp" /> </RelativeLayout>
獲取城市列表