温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android中Spinner如何使用

发布时间:2021-06-26 15:29:34 来源:亿速云 阅读:139 作者:Leah 栏目:移动开发

今天就跟大家聊聊有关Android中Spinner如何使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

如果你是只能手机,大家可以来这里先来了解以下Android系统,作为参考。

//SpinnerDemo.java:  package com.cci.SpinnerDemo;  import android.app.Activity;  import android.os.Bundle;  import android.view.View;  import android.widget.AdapterView;  import android.widget.AdapterView.OnItemSelectedListener;  import android.widget.ArrayAdapter;  import android.widget.Spinner;  import android.widget.TextView;  public class SpinnerDemo extends Activity {      TextView tv;      /** Called when the activity is first created. */      @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);                    tv=(TextView)findViewById(R.id.mytxt);                    ArrayAdapter<String>  adapter = new ArrayAdapter<String>(                  this,android.R.layout.simple_spinner_item);          adapter.setDropDownViewResource(                  android.R.layout.simple_spinner_dropdown_item);                    //随便写什么东西          adapter.add("red");          adapter.add("green");          adapter.add("blue");          Spinner spinner = (Spinner) findViewById(R.id.myspinner);          spinner.setAdapter(adapter);          spinner.setOnItemSelectedListener(new OnItemSelectedListener() {              public void onItemSelected(AdapterView<?> parent,                  View view,int position,long id) {                  Spinner spinner = (Spinner) parent;                  tv.setText(spinner.getSelectedItem().toString());                  //Log.v("Test", "id = " + id + "("                  //+ spinner.getSelectedItem().toString() + ")");                  }              public void onNothingSelected(AdapterView<?> parent) {              }                            });      }  }   <!--main.xml--> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     > <TextView        android:id="@+id/mytxt"     android:layout_width="fill_parent"       android:layout_height="wrap_content"       android:text="@string/hello"     /> <Spinner       android:id="@+id/myspinner"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     ></Spinner> </LinearLayout>

看完上述内容,你们对Android中Spinner如何使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI