這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)如何在Android中使用Spinner下拉菜單控件,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)是網(wǎng)站建設(shè)技術(shù)企業(yè),為成都企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)站設(shè)計(jì),網(wǎng)站制作,網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。十余年品質(zhì),值得信賴!activity_main.xml
MainActivity.java
package com.example.hello; import java.util.ArrayList; import java.util.List; import android.support.v7.app.ActionBarActivity; 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.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView; public class MainActivity extends ActionBarActivity implements OnItemSelectedListener{ private TextView textView; private Spinner spinner; private Listlist; private ArrayAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (TextView) findViewById(R.id.textView); textView.setText("您選擇的城市是:"); spinner = (Spinner) findViewById(R.id.spinner); list = new ArrayList (); list.add("北京"); list.add("上海"); list.add("廣州"); list.add("深圳"); adapter = new ArrayAdapter (this, android.R.layout.simple_spinner_item,list); adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); } @Override public void onItemSelected(AdapterView> arg0, View arg1, int arg2,long arg3) { String cityName = adapter.getItem(arg2); //String city = list.get(arg2); textView.setText("您選擇的城市是:"+cityName); } @Override public void onNothingSelected(AdapterView> arg0) { // TODO Auto-generated method stub } }
上述就是小編為大家分享的如何在Android中使用Spinner下拉菜單控件了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。