【发布时间】:2014-05-10 14:12:36
【问题描述】:
我需要访问线性布局中存在的文本视图并使用 gettext() 打印文本?
布局如下:
线性布局
线性布局
图像视图
相对布局
文本视图
【问题讨论】:
标签: android android-uiautomator
我需要访问线性布局中存在的文本视图并使用 gettext() 打印文本?
布局如下:
线性布局
线性布局
图像视图
相对布局
文本视图
【问题讨论】:
标签: android android-uiautomator
为第一个布局创建一个linearLayoutObject,然后为TextView 创建另一个对象。
UiObject lLayout = new UiObject(new UiSelector().className(LinearLayout.class.getName()).index(1));
UiObject tView = lLayout.getChild(new UiSelector().className(TextView.class.getName()).index(1));
String tDetails = tView.getText();
现在您可以使用tDetails 进行比较或其他目的。
【讨论】:
TextView 周围的布局无关紧要,除非您正在使用他们的 Visibility。
您在其中访问TextView 的Activity 需要调用:setContentView(R.layout.yourLayout);
使用textView= (TextView) findViewById(R.id.textViewId);
映射你的textView 然后可以
textView.getText()
http://developer.android.com/guide/topics/resources/layout-resource.html
http://www.intertech.com/Blog/android-layout-and-id-attribute/
【讨论】: