-1

I have a bunch of Views added programmatically in a loop:

for (int j = 0; j < size(); j++) {
    TextView xxxView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.xxx, container, false);
    xxxView.setId(k++); //this is not enough as UI Automator does not see it, id field is empty in UI Automator 
    container.addView(xxxView);
}

There is about 180 of those Views so it would be quite difficult to create xml with ids but this may be the only solution here.

Maybe some array of ids?

Marian Paździoch
  • 8,813
  • 10
  • 58
  • 103

2 Answers2

0

generate ids with View.generateViewId()

an_droid_dev
  • 1,136
  • 14
  • 18
0

Use something else, like content description or tag.

for (int j = 0; j < size(); j++) {
    TextView xxxView = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.xxx, container, false);
    xxxView.setId(k++); //this is not enough as UI Automator does not see it, id field is empty in UI Automator 
    xxxView.setContentDescription("id:" + k); 
    container.addView(xxxView);
}

Then use UiSelector.description()

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134