如何访问“文本”视图并进行打印

时间:2014-03-31 09:35:30

标签: android uiautomator

我需要访问线性布局中的文本视图并使用gettext()打印文本?

布局如下:

的LinearLayout
   的LinearLayout
      ImageView的
   RelativeLayout的
      TextView的

2 个答案:

答案 0 :(得分:0)

除非您正在使用TextView,否则Visibility周围的布局无关紧要。

您访问Activity的{​​{1}}需要致电:
 TextView

使用setContentView(R.layout.yourLayout);
映射您的textView= (TextView) findViewById(R.id.textViewId);然后可以

textView

http://developer.android.com/guide/topics/resources/layout-resource.html

http://www.intertech.com/Blog/android-layout-and-id-attribute/

答案 1 :(得分:0)

为第一个布局创建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进行比较或其他目的。

相关问题