最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)簡單的城市列表功能

 更新時間:2017年09月28日 09:22:43   作者:程澤翔  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡單的城市列表功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android城市列表簡單用法,供大家參考,具體內(nèi)容如下

步驟:

1. 在app的gradle里面添加依賴:

com.github.andyoom:citypicker:v1.0.4

2.在項(xiàng)目的build.gradle中添加

maven {url "https://jitpack.io"}

開始寫代碼:

xml布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:app="http://schemas.android.com/apk/res-auto" 
  android:orientation="vertical" 
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
  android:layout_height="match_parent" tools:context="com.bwei.czx.czx.MainActivity"> 
 
  <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:text="更換城市" 
    android:id="@+id/btn"/> 
  <TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:textSize="30sp" 
    android:id="@+id/name"/> 
 
 
</LinearLayout> 

MainActivity代碼:

package com.bwei.czx.czx; 
 
import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 
 
import com.example.city_picker.CityListActivity; 
 
public class MainActivity extends AppCompatActivity { 
 
  private TextView tv; 
 
  @Override 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button btn = (Button) findViewById(R.id.btn); 
    tv = (TextView) findViewById(R.id.name); 
    btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
        CityListActivity.startCityActivityForResult(MainActivity.this); 
 
      } 
    }); 
  } 
  @Override 
  protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if(requestCode == 101&& resultCode ==102){ 
      String city = data.getStringExtra("city"); 
      tv.setText(city); 
    } 
  } 
}     

在模擬器中實(shí)現(xiàn)效果:

點(diǎn)擊Button會出現(xiàn)

      

返回會把城市名稱回傳回來,這就實(shí)現(xiàn)了一個簡單的城市列表!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

古田县| 体育| 登封市| 香河县| 革吉县| 策勒县| 正宁县| 沁阳市| 棋牌| 汉中市| 临安市| 什邡市| 依兰县| 梓潼县| 拜城县| 三河市| 秀山| 张家港市| 德江县| 彰化市| 迁安市| 惠安县| 庆云县| 连州市| 淮阳县| 南平市| 合肥市| 如皋市| 栾城县| 积石山| 社旗县| 金乡县| 石台县| 平阳县| 清徐县| 肇东市| 开鲁县| 丹寨县| 仙游县| 改则县| 三江|