Search code examples
androidimageandroid-imageview

How to make a "ImageView" field as mandatory in android?


I have a imageview field in my android app, onclick of the same I have given a "open camera" functionality and the user can click the photo from camera and it gets uploaded to ImageView

  b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if(user_image.getDrawable() == null ){

                Toast.makeText(NewCall4.this, "No image uploaded", Toast.LENGTH_SHORT).show();
            }
            else{

                Intent i=new Intent(NewCall4.this,NewCall5.class);
                startActivity(i);
            }

        }
    }
    );

What I want is, if I am not uploading the image in the imageview then it should give the error/toast message as "Image not uploaded"


Solution

  • You Can check the Drawable if attached to ImageView

    Imageview imageView = (ImageView)findViewById(R.id.image);
    if(imageView.getDrawable() == null){
     //Then Nothing is attached with imageviw
    }