這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)如何在Android中使用Spinner下拉菜單控件,文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)安定,十年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢建站服務(wù):028-86922220
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下拉菜單控件了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。