I try change the background of ImageView
, but it error due to OutOfMemoryError
.
I have search for change the background by using Bitmap
, but I don't know how to use it.
When I click the button , the background will change to the another picture.
The code is like the following:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.user_guide, container, false) ;
last = (Button) view.findViewById(R.id.last);
user = (ImageView) view.findViewById(R.id.image);
last.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
user.setBackgroundResource(R.drawable.test1);
}
});
I have search for the following code , but I don't know hot to use it to change the background
of Imageview
.
Can someone teach me how to use it?
public static Bitmap readBitMap(Context context, int resId){
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is,null,opt);
}
Can someone teach me how to use it to change the background of ImageView
and without OutOfMemoryError
?
Thanks in advance.