I have two different (or not -.-) UiObjects and I want to compare them.
I can see if they are of the same class and that sort of thing but it isn't enough.
I thought of using resource id but I can't find a way to access it (I want to do it in run time so ui automator viewer is of no help...).
So I'm actually asking two things:
Thanks in advance.
EDIT: My idea is to:
Currently, I am able to access the root of the layout tree and, thus, its children (as UiObjects) by choosing the first instance of FrameLayout (true for every screen)
Code Sample:
//I get the first object of the current layout screen by
UiObject obj = new UiObject(new UiSelector().className("android.widget.FrameLayout").instance(0));
/*
code to get rest of the tree ...
*/
/*
code interact with a button
*/
// now I want to see if the screen changed (completely new or if a new widget appeared) or if its the same
// for that I need to know if the objects are the same
// To compare objects I need their id
The reason I hadn't written code is because I don't think it really adds much... As the bit that matters is the one I don't know how to do
Well, I figured out this much:
In summary, what I wanted is indeed impossible.
View class has the "getId" method, you can use it to compare views. For instance, if your class implements OnClickListener, then you can check which view raised the event like this:
public void onClick (View view) {
switch(view.getId()) {
case R.id.my_button_1:
// What to do for button 1.
break;
case R.id.my_button_2:
// What to do for button 2.
break;
default:
// Unknown view
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.