android spinner实例

wolf_xuan

贡献于2014-08-19

字数:2682 关键词: Android开发 移动开发

 package com.turboradio.googlesdk;   import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView;   public class Ex_04_08_spinner extends Activity{ private static final String [] countriesStr = { "北京市","上海市","天津市","重庆市" }; private TextView myTextView; private Spinner mySpinner; private Animation myAnimation; private ArrayAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ex_04_08); myTextView = (TextView)findViewById(R.id.myTextView); mySpinner = (Spinner)findViewById(R.id.mySpinner); adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,countriesStr); adapter.setDropDownViewResource(R.layout.myspinnerdropdown); mySpinner.setAdapter(adapter); mySpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){   public void onItemSelected(AdapterView parent, View view, int position, long id) { myTextView.setText("选择的是:" +  countriesStr[position]); //view.setVisibility(View.VISIBLE); }   public void onNothingSelected(AdapterView arg0) {   }}); /**取得Animation定义的res/anim目录下**/ myAnimation = AnimationUtils.loadAnimation(this, R.anim.my_anim); mySpinner.setOnTouchListener(new Spinner.OnTouchListener(){   public boolean onTouch(View v, MotionEvent event) { /**将mySpinner运行Animation**/ mySpinner.startAnimation(myAnimation); mySpinner.setVisibility(View.INVISIBLE); returnfalse; }}); mySpinner.setOnFocusChangeListener(new Spinner.OnFocusChangeListener(){   public void onFocusChange(View v, boolean hasFocus) {   }}); }   } layout.ex_04_08.xml         myspinnerdropdown.xml   res/anim/ my_anim.xml        

下载文档,方便阅读与编辑

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 1 金币 [ 分享文档获得金币 ]
0 人已下载

下载文档

相关文档