我想使用以下代码设置imageview的背景:
String color = (cursor.getString(cursor.getColumnIndex(NotesDbAdapter.KEY_COLOR)));
ImageView background=(ImageView)view.findViewById(R.id.album_image);
DecodeTask task = (DecodeTask)background.getTag(R.id.album_image);
background.setScaleType(ImageView.ScaleType.CENTER_CROP);
String imageCheck = (cursor.getString(cursor.getColumnIndex(NotesDbAdapter.KEY_IMAGE)));
if (imageCheck != 0){
background.setImageBitmap(BitmapFactory.decodeFile(imageCheck));
}
else if (color != null && !color.isEmpty()){
if (color.equals("1")){
task = new DecodeTask(background);
background.setImageResource(R.drawable.bluebg);
}
else if (color.equals("2")){
task = new DecodeTask(background);
background.setImageResource(R.drawable.greenbg);
}
else if (color.equals("3")){
task = new DecodeTask(background);
background.setImageResource(R.drawable.yellowbg);
}
else if (color.equals("4")){
task = new DecodeTask(background);
background.setImageResource(R.drawable.redbg);
}
else if (color.equals("5")){
task = new DecodeTask(background);
background.setImageResource(R.drawable.purplebg);
}
}
但是当imageCheck等于0时,它不会读取更多代码并设置图像的默认背景。我该怎么办?
答案 0 :(得分:3)
尝试更改
if(imageCheck != 0)
到
if(!imageCheck.equals("0"))
因为您正在比较字符串