亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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)文章

  • Android Studio開發(fā)環(huán)境搭建教程詳解

    Android Studio開發(fā)環(huán)境搭建教程詳解

    android studio是最近比較火的開發(fā),那么android studio開發(fā)環(huán)境怎么搭建呢?下面通過本文給大家記錄下Android Studio開發(fā)環(huán)境搭建教程詳解,需要的朋友參考下吧
    2017-11-11
  • 深入理解Kotlin的泛型系統(tǒng)

    深入理解Kotlin的泛型系統(tǒng)

    Kotlin 泛型即 “參數(shù)化類型”,將類型參數(shù)化,可以用在類,接口,方法上。下面 這篇文章主要給大家介紹了關(guān)于Kotlin泛型系統(tǒng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。
    2017-12-12
  • Android Activity與Fragment之間的跳轉(zhuǎn)實(shí)例詳解

    Android Activity與Fragment之間的跳轉(zhuǎn)實(shí)例詳解

    這篇文章主要介紹了Android Activity與Fragment之間的跳轉(zhuǎn)實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • 怎樣刪除android的gallery中的圖片實(shí)例說明

    怎樣刪除android的gallery中的圖片實(shí)例說明

    長按gallery中的圖片進(jìn)行刪除該圖片的操作,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈
    2013-06-06
  • Android獲取藍(lán)牙設(shè)備列表的方法

    Android獲取藍(lán)牙設(shè)備列表的方法

    這篇文章主要為大家詳細(xì)介紹了Android獲取藍(lán)牙設(shè)備列表的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Android編程之json解析實(shí)例詳解

    Android編程之json解析實(shí)例詳解

    這篇文章主要介紹了Android編程之json解析,結(jié)合實(shí)例形式較為詳細(xì)的分析了了Android針對json格式數(shù)據(jù)的創(chuàng)建、讀取與解析技巧,需要的朋友可以參考下
    2015-12-12
  • 最新評論