1. 程式人生 > >Android中呼叫第三方實現美團城市選擇

Android中呼叫第三方實現美團城市選擇

    1.新增依賴

compile 'com.zaaach:citypicker:1.1'
    2.清單檔案中新增
<activity
android:name="com.zaaach.citypicker.CityPickerActivity"
android:screenOrientation="portrait"
android:theme="@style/CityPicker.NoActionBar"
android:windowSoftInputMode="stateHidden|adjustPan" />

<!--這裡的value要替換成你專案的-->
<meta-data android:name="com.amap.api.v2.apikey" android:value="138e5cf1e8961ae326ff0908c03d1ae1" />
    3.MainActivity中
startActivityForResult(new Intent(MainActivity.this, CityPickerActivity.class), REQUEST_CODE_PICK_CITY);

   //點選傳值

@Override
public void onActivityResult(int requestCode, int 
resultCode, Intent data) { if (requestCode == REQUEST_CODE_PICK_CITY && resultCode == RESULT_OK){ if (data != null){ String city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY); } } }