Android 如何为循环中创建的视图设置唯一ID,以便UI Automator可以看到它们

Android 如何为循环中创建的视图设置唯一ID,以便UI Automator可以看到它们,android,android-view,android-uiautomator,programmatically-created,Android,Android View,Android Uiautomator,Programmatically Created,我在循环中以编程方式添加了一组视图: 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 fie

我在循环中以编程方式添加了一组视图:

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);
}
for(int j=0;j
其中大约有180个视图,因此很难创建,但这可能是唯一的解决方案


可能是一些ID数组?

使用
视图生成ID。generateView()
使用其他内容,如内容描述或标记

for(int j=0;j

然后使用

这将不起作用,因为当我使用View.generateView()时,ID有点随机。
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);
}