标签:android style blog color io ar cti div
方法一代码如下:
<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)); }
标签:android style blog color io ar cti div
原文地址:http://www.cnblogs.com/tplovejava/p/3920714.html