`

android Spinner

 
阅读更多

基本设置参照 http://imshare.iteye.com/blog/770950

页面显示的内容和弹出框不同的设置:

	titleSpinner.setPrompt("请选择服务网点范围:");  //设置弹出框提示信息
	titleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

		@Override
		public void onItemSelected(AdapterView<?> parent, View view,
				int pos, long id) {
			// TODO Auto-generated method stub
			TextView txtView = (TextView)view;
			txtView.setText("办税服务网点("+listSpinner.get(pos)+")");
		}		
	}		

spinner 样式自定义参考

http://www.pocketdigi.com/20111206/587.html

只要提供显示样式和弹出样式就可以实现不同效果

显示样式设置

spinnerAdapter = new ArrayAdapter<String>(this,R.layout.spinner_style, listSpinner); 

R.layout.spinner_style是自定义样式

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
	style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
	android:textColor="#FFFFFF"
    android:ellipsize="marquee" />

 弹出样式设置

spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

android.R.layout.simple_spinner_dropdown_item 这个是系统定义的样式,也可以自定义一个样式类似下面的

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml
**
** Copyright 2008, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee" />

更多参考http://www.android-doc.com/reference/android/widget/Spinner.html

              http://blog.csdn.net/pathuang68/article/details/6404461

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics