编写自定义的 Android Preference 组件
2010-05-28 15:00:00 来源:WEB开发网public ImageOptionPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ImageOptionPreference(Context context) {
super(context);
}
void setActivity(PreferenceActivity parent) {
this.parent = parent;
}
@Override
public boolean isPersistent() {
return false;
}
/**
* 修改图片
* @param newImage
* @return
*/
boolean ChangeGamePic(int newImage ){
if(this.mImage == newImage)
return false;
GameGlobal.save_pic(newImage);
this.mImage = newImage;
preview_img.setImageResource(newImage);
return true;
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
this.mImage = GameGlobal.get_pic();
preview_img = (ImageView)view.findViewById(R.id.pref_current_img);
preview_img.setImageResource(this.mImage);
}
@Override
protected void onClick() {
super.onClick();
Bundle bundle = new Bundle();
bundle.putInt(GameGlobal.PREF_KEY_IMAGE, this.mImage);
Intent intent = new Intent(parent, ImageSelector.class);
intent.putExtras(bundle);
parent.startActivityForResult(intent, MagicSetting.REQUEST_CODE_GAME_IMAGE);
}
}
对应的 Perference 配置信息如下
< com.liusoft.android.fmagic.ImageOptionPreference
android:key="game_pic"
android:persistent="false"
android:title="@string/pref_pic_title"
android:summary="@string/pref_pic_summary"
android:widgetLayout="@layout/preference_widget_image"
/ >
而 preference_widget_image 的信息如下
< ?xml version="1.0" encoding="utf-8"? >
更多精彩
赞助商链接