• 安卓app_sl3_17列表选择框Spinner


    获取选中额选项的值。

    <!-- array.xml -->
    <resources>
    
        <!--
            Base application theme, dependent on API level. This theme is replaced
            by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
        -->
        <style name="AppBaseTheme" parent="android:Theme.Light">
            <!--
                Theme customizations available in newer API levels can go in
                res/values-vXX/styles.xml, while customizations related to
                backward-compatibility can go here.
            -->
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        </style>
        <string-array 
            name="ctype">
            <item>身份证</item>
            <item>学生证</item>
            <item>军人证</item>
            <item>工作证</item>
            <item>其他</item>
        </string-array>
    
    </resources>
    <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.sl3_17.MainActivity" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30dp"
            android:text="@string/hello_world" />
    
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"        
            android:layout_toRightOf="@+id/textView1"       
            android:entries="@array/ctype" 
            />
    
    </RelativeLayout>
    package com.example.sl3_17;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.Spinner;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            final Spinner spinner=(Spinner)findViewById(R.id.spinner1);
            spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    // TODO 自动生成的方法存根
                    //Toast.makeText(MainActivity.this, spinner.getSelectedItem().toString(),Toast.LENGTH_SHORT).show();
                 String result=parent.getItemAtPosition(position).toString();
                 Toast.makeText(MainActivity.this, result, Toast.LENGTH_SHORT).show();
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    // TODO 自动生成的方法存根
                    
                }
                
            });
            
            
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            // Handle action bar item clicks here. The action bar will
            // automatically handle clicks on the Home/Up button, so long
            // as you specify a parent activity in AndroidManifest.xml.
            int id = item.getItemId();
            if (id == R.id.action_settings) {
                return true;
            }
            return super.onOptionsItemSelected(item);
        }
    }
  • 相关阅读:
    windows下 安装 rabbitMQ 及操作常用命令
    C#中关于DataGridView行和列的背景色-前景色设置
    使用Linq判断DataTable数据是否重复
    C#用mouse_event模拟鼠标点击的问题
    ApartmentState.STA
    使用WebBrowser,内存一直增加的解决办法
    HOT SUMMER 每天都是不一样,积极的去感受生活 C#关闭IE相应的窗口 .
    您访问的URL地址不被允许。
    CMSIS-DAP for STLink V2.1 and STLink v2.1 mini adapter
    DG449 High Voltage Single SPDT Analog Switch in SOT23-8
  • 原文地址:https://www.cnblogs.com/txwtech/p/15911377.html
Copyright © 2020-2023  润新知