Android Question Resource-Id missing from most views

walterf25

Expert
Licensed User
Longtime User
Hi all, i'm in the middle of wrapping a library used to do some UI Elements Inspection automation, one of the ways to look for elements in an apk file is by Resource-Id, does anyone know how are this names or IDs assigned to a layout, is there a way for us to manually assign this IDs ourselves, attached are some images i took using the UI Automation Viewer that comes with Android SDK, and while inspecting the views I can see that none of the views on the first screenshot have a Resource-Id name, but in the second screenshot on the AlertDialogBox you can see that there are some views which have a Resource-Id assigned to them.

Is this a difference between an app created with B4A and Android Studio?

ResourceID.PNG
AlertDialog.PNG

Any thoughts?
 

Semen Matusovskiy

Well-Known Member
Licensed User
You can set R.id in run time.
For example
B4X:
Dim jo As JavaObject = EditText1
Dim id As Int = jo.RunMethod ("generateViewId", Null)   
jo.RunMethod ("setId", Array (id))
Log (jo.RunMethod ("getId", Null))
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
You can set R.id in run time.
For example
B4X:
Dim jo As JavaObject = EditText1
Dim id As Int = jo.RunMethod ("generateViewId", Null)  
jo.RunMethod ("setId", Array (id))
Log (jo.RunMethod ("getId", Null))
This is good to know, but i wonder why this is not implemented at the time of creating the views either in the designer as a property or programmatically when creating views, anyhow for the tool i'm wrapping the library for this would be a great thing to have as it would make things a lot easier.

Regards,
Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Guess, you can place this wish in https://www.b4x.com/android/forum/forums/bugs-wishlist.30/
Sure, it's not hard for B4A to integrate similar feature.

But from another side ... Many persons do not use Visual Designer at all and to use names of fields is more simple than numeric id.
from what I understand the Resource-Id i'm referring to is a regular text name that is given to each view, if you look at the images i posted in the first post you can see on the second screenshot that the Resource-Id for the dialogbox title is a string and not a numeric id.

Regards,
Walter
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
second screenshot that the Resource-Id for the dialogbox title is a string and not a numeric id
no, it is not an String. the id is a numeric value In this case the numeric value is pointing to a Resource. Here the resource is a String. But the reference to it is a Integer
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
You can set R.id in run time.
For example
B4X:
Dim jo As JavaObject = EditText1
Dim id As Int = jo.RunMethod ("generateViewId", Null)  
jo.RunMethod ("setId", Array (id))
Log (jo.RunMethod ("getId", Null))
So I tried this and while it works and sets the Resource Id, i still don't see it when I inspect the views with UIAutomatorViewer, it must be a B4A thing that does not let the Resource Id be set.

Walter
 
Upvote 0
Top