我在循环中以编程方式添加了一堆视图:
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);
}
这些视图大约有180个,因此创建xml with ids非常困难,但这可能是此处唯一的解决方案。
也许有一些ID?
答案 0 :(得分:0)
使用View.generateViewId()
答案 1 :(得分:0)
使用其他内容,例如内容说明或标记。
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);
}