zoukankan      html  css  js  c++  java
  • Spinner

    <resources>
        <string name="app_name">HelloWorld</string>
    
        <string-array name="city_labels">
            <item>北京</item>
            <item>上海</item>
            <item>广州</item>
            <item>深圳</item>
        </string-array>
    </resources>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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"
        android:orientation="vertical"
        tools:context="com.pingyijinren.helloworld.MainActivity">
    
        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:entries="@array/city_labels"
            android:id="@+id/spinner"></Spinner>
    </LinearLayout>
    package com.pingyijinren.helloworld;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.Spinner;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
        private Spinner spinner;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            spinner=(Spinner)findViewById(R.id.spinner);
            spinner.setPrompt("选择你所在的城市");
            spinner.setOnItemSelectedListener(this);
        }
    
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String[] cities=getResources().getStringArray(R.array.city_labels);
            Toast.makeText(this,cities[position]+"",Toast.LENGTH_SHORT).show();
        }
    
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    }
  • 相关阅读:
    poj 1743 Musical Theme 后缀数组
    poj 1743 Musical Theme 后缀数组
    cf 432D Prefixes and Suffixes kmp
    cf 432D Prefixes and Suffixes kmp
    hdu Data Structure? 线段树
    关于position和anchorPoint之间的关系
    ios POST 信息
    CALayers的代码示例
    CALayers详解
    ios中得sqlite使用基础
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5552359.html
Copyright © 2011-2022 走看看