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) {
        }
    }
  • 相关阅读:
    1. C/C++项目一
    3. C/C++笔试面试经典题目三
    1. C/C++笔试面试经典题目一
    Win7下C/C++跨平台开发工具IDE的安装之Eclipse-CDT
    Win7下C/C++跨平台开发工具IDE的安装之CodeBlocks
    css
    form表单,选择器
    html介绍
    元类
    事务、视图、触发器、存储过程、函数、数据库的备份
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5552359.html
Copyright © 2011-2022 走看看