zoukankan      html  css  js  c++  java
  • 事件(3)

    下拉框:OnItemSelectedListener

      sp.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override    

        public void onItemSelected(AdapterView<?> arg0, View view,int arg2, long arg3) {

          TextView tv1=(TextView)view;
          String str=tv1.getText().toString();
          tv.setText(str);
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {


        }
      });

     1 package com.hh;
     2 
     3 import android.app.Activity;
     4 import android.os.Bundle;
     5 import android.view.View;
     6 import android.widget.AdapterView;
     7 import android.widget.Spinner;
     8 import android.widget.TextView;
     9 import android.widget.AdapterView.OnItemSelectedListener;
    10 
    11 public class Click extends Activity{
    12     private TextView tv;        //定义信息显示组件
    13     private Spinner sp;
    14         
    15         sp=(Spinner) findViewById(R.id.spe1);
    16         sp.setOnItemSelectedListener(new OnItemSelectedListener() {
    17 
    18             @Override
    19             public void onItemSelected(AdapterView<?> arg0, View view,
    20                     int arg2, long arg3) {
    21                 TextView tv1=(TextView)view;
    22                 String str=tv1.getText().toString();
    23                 tv.setText(str);
    24             }
    25 
    26             @Override
    27             public void onNothingSelected(AdapterView<?> arg0) {
    28                 
    29             }
    30         });
    31 }
    代码示例
     1  <TextView
     2           android:id="@+id/tve1"
     3         android:layout_width="fill_parent" 
     4         android:layout_height="wrap_content" 
     5            android:background="#FF0000"
     6       />
     7       
     8       <Spinner
     9           android:id="@+id/spe1"
    10         android:layout_width="fill_parent" 
    11         android:layout_height="wrap_content" 
    12         android:entries="@array/citys"
    13       />
    xml配置文件

  • 相关阅读:
    php的下载与安装
    apache 的下载与配置
    Composer 安装与使用
    WampServer 的安装
    SQLServer主键约束和唯一约束的区别
    Mac如何修改Host
    解决XCode11中 [Application] The app delegate must implement the window property if it wants to use a main storyboard file.的问题
    Xcode10.1 import头文件无法索引
    iOS
    如何让windows服务器IIS支持.apk/.ipa文件下载
  • 原文地址:https://www.cnblogs.com/yang82/p/6964663.html
Copyright © 2011-2022 走看看