-1

I have an ImageView in xml like this, and it has drawable globe1 attached in xml :

                 <ImageView
                    android:layout_margin="10dp"
                    android:id="@+id/ppImageView"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    app:srcCompat="@drawable/globe1"
                    
                    />

Then I set an image bitmap dynimacally from java in that ImageView :

ppImageView.setImageBitmap(ppBitmap);

So, my question is how do I check that ppImageView contains globe1 or ppBitmap ?

I have checked this question, but, seems that it does not fit my situation.

Noor Hossain
  • 1,620
  • 1
  • 18
  • 25

1 Answers1

0

Alhamdulillah, I have found the solution. What I do that, I have attached tag in xml:

                <ImageView
                    android:layout_margin="10dp"
                    android:id="@+id/iv_uphoto"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    app:srcCompat="@drawable/globe1"
                    android:tag="globe1"
                    />

And When I Attached Image dynamically, I also set another tag :

 ppImageView.setImageBitmap(ppBitmap);
  ppImageView.setTag("ppImageView");

Then I check the Tag this Way :

if(hasImage(ppImageView, "ppImageView" )){

            System.out.println("ppImageTag: "+(String)ppImageView.getTag());
                System.out.println("Image Attached in ppImageView");
                // now do your Work : 
                

        }else {
            Toast.makeText(ProfilePageTeacher.this,"Please Attach Appropriate PassPort Image",Toast.LENGTH_LONG).show();
            return;
        }

And the hasImage method as follows :

private boolean hasImage(@NonNull ImageView view, String tag) {

        String previousTag = (String) view.getTag();

        return previousTag.equalsIgnoreCase(tag);


    }
Noor Hossain
  • 1,620
  • 1
  • 18
  • 25