Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:21+00:00 2026-05-26T12:59:21+00:00

I have an ImageButton which on click i show a dialog box where users

  • 0

I have an ImageButton which on click i show a dialog box where users can either take a photo from the camera or choose from the gallery. On selecting image from either sources i setBitmap for that ImageButton to the image selected like this

SelectedPhoto = BitmapFactory.decodeFile(selectedImagePath);
DisplayPhoto.setImageBitmap(SelectedPhoto);

Now when some one has already selected an image and click the image again i want to show a different dialog which contains a third option “Remove Photo”.

What property of the image button should i check and against what ?

ImageButton in XML

<ImageButton
                android:id="@+id/DisplayPhoto"
                android:layout_width="95dip"
                android:layout_height="95dip"
                android:layout_marginRight="8dip"
                android:background="@drawable/signup_photo_selector" android:scaleType="centerCrop" />

ImageButton Background XML

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/signup_form_photo_selected" android:state_pressed="true"/>
    <item android:drawable="@drawable/signup_form_photo"/>
</selector>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:59:22+00:00Added an answer on May 26, 2026 at 12:59 pm

    Would imgButton.getDrawable() work, since it returns null if no drawable has been assigned to the imagebutton?

    If not, or if you don’t want to get the entire drawable just to see if it’s there, you can use a tag. imgButton.setTag(object) lets you store any object within the imagebutton… every time you set its background, you can tag a value that identifies whether its background was set. You could even use different values to differentiate whether you set its background using a camera or from the gallery, if that’s useful. When you want to see if the imagebutton has a background or not, use imgButton.getTag() to retrieve the object.

    Edit. Here is how you would use setTag and getTag. I will use an Integer object as the ImageButton’s tag, where a value of 0 indicates no background has been set and a value of 1 indicates a background has been set. You can use an enum or final variables if you want to make the code a bit clearer, but using an Integer will work as an example.

    public class MainActivity extends Activity, implements OnClickListener {
      private ImageButton imgButton;
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        imgButton = (ImageButton)findViewById(R.id.imgID);
        imgButton.setTag(new Integer(0)); // no background
        ...
      }
    
      public void onClick(View view) {
        ImageButton ib = (ImageButton)view;
        int hasBackground = ib.getTag().intValue();
    
        if(hasBackground==0) {
          // imagebutton does not have a background. do not include remove option
          ...
        } else {
          // imagebutton has a background. include remove option
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which creates an ImageButton and plays a sound when
I have an asp:ImageButton that is supposed to popup a save dialog when clicked.
If you have time , please can you take some time for me ?
I have a slide show which is made up of a divs. Each Div
I have an <asp:ImageButton /> which has its enabled property set to false .
I have a image button in a page which can be triggered on mouse
To change the language I click on an imageButton which executes something like: SetCulture(Session,
I have successfully implemented a multi-language website in which user can change language by
In my child page i have an imageButton, which is surrounded by the UpdatePanel.
I have a surfaceview which is displaying a camera preview I have it taking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.