zoukankan      html  css  js  c++  java
  • spinner下拉框组件

    方法一代码如下:

    <string-array name="city_name">
            <item>浙江</item>
            <item>上海</item>
            <item>北京</item>
        </string-array>
    <Spinner 
            android:id="@+id/citySelect"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:entries="@array/city_name"
            />
    entries="@array/city_name"指定数组资源

    方法二适配器设置:
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mCitySelect = (Spinner) findViewById(R.id.citySelect);
        
            mCitySelect2 = (Spinner) findViewById(R.id.citySelect2);
            String arr[] = {"孙悟空", "猪八戒", "唐曾"};
            adapter = new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, arr);
            //为适配器设置下拉样式
            adapter.setDropDownViewResource(android.R.layout.simple_selectable_list_item);
            mCitySelect2.setAdapter(adapter);
            
            mCitySelect2.setOnItemSelectedListener(this);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            mTxtShow = (TextView) findViewById(R.id.txtShow);
            mTxtShow.setText("您选择的是:"+adapter.getItem(arg2));
        }


  • 相关阅读:
    抗变与协变
    border-width实现博客园回复效果
    福利到!分享我的分页控件
    linq distinct 不够用了!
    sql server 使用nolock提升性能
    Graph-Based image segmentation method
    纹理特征提取【转】
    ROC曲线【转】
    LBP纹理特征[转自]
    SPAMS:稀疏建模工具箱
  • 原文地址:https://www.cnblogs.com/tplovejava/p/3920714.html
Copyright © 2011-2022 走看看