编写自定义的 Android Preference 组件
2010-05-28 15:00:00 来源:WEB开发网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);
}
}
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
/**
* 图片选项,用于设置图片和边框
* @author Winter Lau
*/
public class ImageOptionPreference extends Preference {
private PreferenceActivity parent;
private int mImage = R.drawable.car;
private ImageView preview_img;
public ImageOptionPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
更多精彩
赞助商链接