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 8871003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:52:17+00:00 2026-06-14T17:52:17+00:00

Method being Tested (In Main Activity) //This Method allows you to set the LeftDrawable

  • 0

Method being Tested (In Main Activity)

//This Method allows you to set the LeftDrawable Image to a grayed out (drawableDown)
//image for 300 millseconds then returns the LeftDrawable Image back to the orignal 
//(drawableUp).On a button.

void buttonPressFeedbackLeft(final Button button, final int drawableDown,
        final int drawableUp) {
    button.setCompoundDrawablesWithIntrinsicBounds(drawableDown, 0, 0, 0);

    button.postDelayed(new Runnable() {
        public void run() {
            button.setCompoundDrawablesWithIntrinsicBounds(drawableUp, 0,
                    0, 0);
        }
    }, 300);
}

Test in Test Project: (activity and i (intent) already set)

public void testbuttonPressFeedback(){
         /*
          * Start activity
          */
         activity = startActivity(i, null, null);

         /*
          * get the backButton
          */
         Button backButton = (Button) activity.findViewById(R.id.bottem_bar_prev);

         /*
          * get the backButton image (up and down image) as a Drawable
          */
         int drawableDown = R.drawable.ic_menu_back_gray;
         int drawableUp = R.drawable.ic_menu_back;
         /*
          * create a Drawable with the ResId
          */
         Drawable drawableDownImage = activity.getResources().getDrawable(drawableDown);
         Drawable drawableUpImage = activity.getResources().getDrawable(drawableDown);

         /*
          * Simulate button being pressed (running the buttonPressFeedback() method)
          */
         activity.buttonPressFeedbackLeft(prevButton, drawableDown, drawableUp);

         /*
          * get the drawable array [left, top, right, bottom]
          * compare drawable with the drawable found on the button.
          */
         Drawable[] d = prevButton.getCompoundDrawables();
         assertEquals(drawableDownImage,d[0]);
 }

Stack Trace:

junit.framework.AssertionFailedError:
expected:android.graphics.drawable.BitmapDrawable@413e7428 but
was:android.graphics.drawable.BitmapDrawable@413e75c0

Question

I am assuming that the objects are not the same. So I have tried to look into getting the resource Id and comparing them but I don’t think this is possible?

Is there another way to compare the Drawable which is being displayed on the Button?

  • 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-06-14T17:52:18+00:00Added an answer on June 14, 2026 at 5:52 pm

    Sadly this not possible without any work in your code, as you correctly note there is no way to get the drawables resource ID from it. What you are going to have to do is in your code that sets the drawable have it do something like set a tag on the imageview and use that to check it has the correct tag. It is possible that this might be lying to you though and is not an exact test but as long as you test all the states of this button and what drawable should be shown it is likely to be sufficient. So after you set the Drawable id on the same view call the setTag(R.id.xxx) to give it the int that relates to the drawabe you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i run this code the paintComponent method is not being called It may
I'd like to generate method-chaining setters (setters that return the object being set), like
I'm using jQuery's .css() method to set the background image of a div .
I have got a textbox on a form with a method being called from
How do I prevent a method from being overridden in a derived class? In
Am I correct that the only way to prevent a method from being executed
My animationDidStop method is not being called for some reason, initially I thought it
I have an exception being thrown from a C# method, that takes a generic
Is there a method to detect what APIs are being called? Say I wanted
I've got a div being animated on hover (I'm using jquery's .hover() method). The

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.