我有两种适用于手机和平板电脑的布局,均来自单一代码。
...
<Spinner
android:id="@+id/spin_font_sizes"
android:layout_width="0px"
android:layout_height="0px"
android:entries="@array/lst_editor_font_sizes" />
...
在这两种布局中我都定义了一个隐藏的Spinner,以下代码适用于手机,但不适用于平板电脑: 微调器显示在手机上,但点击它不会触发监听器事件。
spin_font_sizes=(Spinner)findViewById(R.id.spin_font_sizes);
spin_font_sizes.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// THIS IS NOT CALLED ON PHONE!
Resources res=getResources();
String[] arr = res.getStringArray(R.array.lst_editor_font_sizes);
float size= Float.parseFloat(arr[arg2]);
editor.setTextSize(TypedValue.COMPLEX_UNIT_PT,size);
SharedPreferences settings = getSharedPreferences("Abrar.Editor", 0);
Editor edt = settings.edit();
edt.putFloat("editorFontSize", size);
edt.commit();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
有时我在日志中看到此错误:
03-30 11:03:03.528: W/InputEventReceiver(8958): Attempted to finish an input event but the input event receiver has already been disposed.