layout.xml

<!-- 添加下拉框 -->
<TextView android:id="@+id/xuanze" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/xuanze"/>

<Spinner android:id="@+id/spinner" android:layout_height="wrap_content"

android:layout_width="wrap_content"/>

Layout.java

private Spinner mSpinner;

private static final String[] status = new String[3];

mSpinner = (Spinner)findViewById(R.id.spinner);
// mSpinner.setOnItemSelectedListener(mFontSizeChanged);
status[0] = "小";
status[1] = "中";
status[2] = "大";
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,status);
mSpinner.setAdapter(adapter) ;
//获取初始值回显
final SharedPreferences preferLoad = getSharedPreferences("settingData",Context.MODE_PRIVATE);
zhuti = preferLoad.getString("zhuti", ResourceManager.getString(getApplicationContext(), "zhuti"));
System.err.println(">>>>>回显值"+zhuti);
mSpinner.setSelection(Integer.parseInt(zhuti));//初始选中的值
mSpinner.setOnItemSelectedListener(new SpinnerSelectedListener());//添加事件

/**
* 下拉框选中后触发事件
*
*/
class SpinnerSelectedListener implements OnItemSelectedListener{
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
System.err.println("选择为>>>>"+status[arg2]);
if(zhixing){
final SharedPreferences preferLoad = getSharedPreferences("settingData",Context.MODE_PRIVATE);
Editor editor=preferLoad.edit();
editor.putString("zhuti", String.valueOf(arg2));
editor.commit();
Intent intent = new Intent(SystemSettingAct.this ,SystemSettingAct.class);
startActivity(intent);
}else{
zhixing = true;
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
}


更多相关文章

  1. Android中设置activity的background为Wallpaper
  2. Android上用TextView实现跑马灯
  3. ListView常用方法整理
  4. Android: Android中各种onTouch事件
  5. Android: Android中各种onTouch事件
  6. Android(安卓)中 drawable下的 android:state 属性
  7. android:Button添加图片
  8. android FrameLayout响应了下层view的点击事件
  9. 12.16 android textView 跑马灯

随机推荐

  1. android 自定义控件继承TextView
  2. Android(安卓)MeterDesign(一)
  3. Android(安卓)Opengl 学习笔记 01——环
  4. Android(安卓)SDK 无法更新解决办法
  5. viewpager实现画廊(一屏多个Fragment)效
  6. Android(安卓)自定义View——自定义一个
  7. Android数据手册02:android.permission权
  8. Android之内存溢出(Out Of Memory)的总结
  9. android编译某个模块
  10. Andorid读写全局配置文件的方法