how to check if an ImageView is attached with image in android

后端 未结 7 1567
半阙折子戏
半阙折子戏 2020-12-13 05:43

I am setting an image to ImageView in android code not in xml, but could not make out how to check whether that image has been set in or not in java.

Tried with

7条回答
  •  鱼传尺愫
    2020-12-13 06:13

    ImageView myImage = (ImageView) findViewById(R.id.imageView);
    
    if (myImage.getDrawable() == null){
    
    //The imageView is empty
    
    } else{ 
    
    
    // The imageView is occupied.
    
    }
    

    or

    ImageView myImage = (ImageView) findViewById(R.id.imageView);
    
    if ( null == myImage.getDrawable()){
    
    //The imageView is empty
    
    } else{ 
    
    
    // The imageView is occupied.
    
    }
    

提交回复
热议问题