【问题标题】:How can i access a Text view and print如何访问文本视图和打印
【发布时间】:2014-05-10 14:12:36
【问题描述】:

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

布局如下:

线性布局
线性布局
图像视图
相对布局
文本视图

【问题讨论】:

    标签: android android-uiautomator


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      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/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-06-03
        • 1970-01-01
        • 2014-04-10
        • 1970-01-01
        • 1970-01-01
        • 2011-02-28
        • 1970-01-01
        相关资源
        最近更新 更多