0

I'm using Robotium to test a screen containing ImageButton switches in an Android app. I have two ImageButtons that use two PNG images (on.png and off.png) to display the state of the switches. I'm trying to find a method that will return the file name of the currently displayed image so I can run a test like:

Get the image being displayed by ImageButton1
Verify that the image is "on.png"
Set ImageButton1 to editable state
Select ImageButton1
Get the image being displayed by ImageButton1
Verify that the image is "off.png"

How do I verify that the correct image file is being displayed by the ImageButton in the correct situation?

BTW, the image is being set in the XML element.

TimM
  • 1
  • 2

2 Answers2

0

I suggest you to take a look at: View.#getDrawableState

It should work like:

boolean on = imageButton.getDrawableState()[your.R.id.state_on] == 1;
boolean off = imageButton.getDrawableState()[your.R.id.state_off] == 1;

You can also check similar question

Community
  • 1
  • 1
maszter
  • 3,680
  • 6
  • 37
  • 53
  • Can you give me more detail for this solution? According to the developer writing the code, there is no state of the imageButton, only the image being displayed. So how can I determine the [your.R.id.state_on] part of this variable assignment? – TimM Apr 03 '14 at 15:24
-1
ImageButton1.getResource().toString();
StarsSky
  • 6,721
  • 6
  • 38
  • 63
Technivorous
  • 1,682
  • 2
  • 16
  • 22
  • Wouldn't this get all of the resource images (among other things), whether they are being displayed or not? – TimM Apr 03 '14 at 12:51