Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用else if语句设置imageview的背景_Java_Android_Imageview - Fatal编程技术网

Java 使用else if语句设置imageview的背景

Java 使用else if语句设置imageview的背景,java,android,imageview,Java,Android,Imageview,我想使用以下代码设置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

我想使用以下代码设置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时,它不会读取进一步的代码,并为图像设置默认背景。我该怎么办

试试换衣服

if(imageCheck != 0)

因为您正在比较字符串

请尝试更改

if(imageCheck != 0)


因为您正在比较字符串

比较字符串和整数?比较字符串和整数?