简体   繁体   中英

How can I add unique IDs to generated views in Android?

I'm an Android developer who's been assigned the task of helping out our QA with automation using Appium.

Our QA has run into an issue where they want to obtain a view that has a particular background color. These views are generated by a server response and as such none of the views have a unique ID.

How can I add unique IDs to generated views in Android to make automation easier?

You can generate unique view ids at runtime via View.generateViewId() and set them onto the new View via view.setId(newId); .

Having said that, can't you keep track of a mapping between background color and Views? Whenever you insert a new View with a specific background color, add it to a map. In your test code you retrieve the particular View (or Views) by using the background color as key.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM