如何用意式浓缩咖啡选择:适配器中的一项,出现在活动框架布局内的片段中?

迪内什(Dinesh)

我的应用程序具有MainActivity,该框架具有充当容器的framelayout。

在屏幕之间导航时,我使用此容器填充不同的片段。现在,在这些片段之一中

主要活动:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include layout="@layout/toolbar" />


    <android.support.v4.widget.DrawerLayout
        android:layout_width="match_parent"
        android:id="@+id/drawerLayout"
        android:layout_height="match_parent">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!-- Framelayout to display Fragments -->
            <FrameLayout
                android:id="@+id/frame_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>


        </FrameLayout>



        <!-- navigation drawer -->
        <RelativeLayout
            android:layout_gravity="left"
            android:layout_width="match_parent"
            android:background="#fff"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/left_drawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#fff"
                android:dividerHeight="1dp"
                android:divider="@drawable/transparent"
                />
        </RelativeLayout>

    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

片段:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:customfont="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipeContainerNewFaces"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@android:id/list"
            android:layout_alignParentTop="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:cacheColorHint="#00000000"
            android:divider="@null"
            android:listSelector="@android:color/transparent"
            android:background="@color/main_bg">
        </ListView>

    </android.support.v4.widget.SwipeRefreshLayout>



    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_publisher_id_radar"/>


    <fr.castorflex.android.smoothprogressbar.SmoothProgressBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/progressBar"
        android:layout_width="match_parent"
        android:layout_height="6dp"/>

    <LinearLayout
        android:id="@+id/layoutRequestTimeout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical"
        android:layout_margin="20dp"
        android:visibility="invisible" >

        <io.newfaces.layout.MyTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:gravity="center_vertical"
            android:textSize="30sp"
            android:textColor="@color/app_main_color"
            customfont:fontName="Lato-BoldItalic.ttf"
            android:text="@string/radar_no_connection_title"/>

        <io.newfaces.layout.MyTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:textSize="16sp"
            android:textColor="@color/black"
            android:gravity="center"
            customfont:fontName="Lato-ThinItalic.ttf"
            android:text="@string/radar_no_connection_message"/>

        <ImageView
            android:id="@+id/ivReloadRadar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="20dp"
            android:src="@drawable/ic_nav_refresh"/>

    </LinearLayout>

</RelativeLayout>

我有一个布局如下的适配器:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/row_story_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:customfont="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:background="#f1f1f1"
    android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:id="@+id/storiesHeader"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="horizontal"
    android:background="#ffffff"
    android:layout_marginTop="5.2dp">
    <FrameLayout
        android:id="@+id/storiesHeaderprofileImage"
        android:layout_weight="0.025"
        android:layout_marginLeft="10.1dp"
        android:layout_width="40dp"
        android:layout_height="50dp">
        <View
            android:id="@+id/storiesViewChatBorder"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/border_not_visible"
            android:layout_gravity="center_vertical"/>
        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/storiesProfilePicture"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical"
            android:src="@drawable/com_facebook_profile_default_icon"
            android:transitionName="my_transition"/>
    </FrameLayout>
    <LinearLayout
        android:id="@+id/storiesHeaderProfileInfo"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_marginLeft="6.2dp"
        android:layout_gravity="center_vertical"
        android:layout_weight="0.8">
        <io.newfaces.layout.MyTextView
            android:id="@+id/storiesName"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:gravity="center_vertical"
            android:textColor="#434343"
            android:text="Dinesh"
            android:textSize="14sp"
            android:layout_weight="0.6"
            customfont:fontName="Lato-BoldItalic.ttf"/>
    </LinearLayout>
    <LinearLayout
        android:id="@+id/storiesHeaderDistance"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:orientation="vertical"
        android:layout_marginRight="12.5dp"
        android:layout_weight="0.175">
        <io.newfaces.layout.MyTextView
            android:id="@+id/storiesDate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#000000"
            android:textSize="12sp"
            android:layout_weight="0.6"
            android:gravity="center_vertical|right"
            customfont:fontName="Lato-BoldItalic.ttf" />
        <io.newfaces.layout.MyTextView
            android:id="@+id/storiesLocation"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-18dp"
            android:textColor="#797979"
            android:textSize="12sp"
            android:layout_weight="0.4"
            android:gravity="center_vertical|right"
            customfont:fontName="Lato-MediumItalic.ttf"/>
    </LinearLayout>
</LinearLayout>
    <RelativeLayout
        android:id="@+id/storiesBody"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#f8f8f8"
        android:layout_below="@+id/storiesHeader">
        <RelativeLayout
            android:id="@+id/storiesBodyOnlyTextLayout"
            android:layout_width="match_parent"
            android:layout_height="250dp">
            <io.newfaces.layout.MyTextView
                android:id="@+id/storyTextOnly"
                android:layout_marginTop="110dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="24.5sp"
                android:textColor="#000000"
                android:textStyle="italic"
                customfont:fontName="Lato-MediumItalic.ttf"
                android:gravity="center"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true" />
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/storiesBodyImageTextLayout"
            android:layout_width="match_parent"
            android:layout_height="250dp">
            <ImageView
                android:id="@+id/storyImage"
                android:scaleType="centerCrop"
                android:layout_width="match_parent"
                android:layout_height="250dp" />
            <View
                android:id="@+id/gradient"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:alpha="0.5"
                android:background="@drawable/gradient" />
            <io.newfaces.layout.MyTextView
                android:id="@+id/storyTextWithImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="14.9dp"
                android:layout_marginRight="42.2dp"
                android:layout_marginBottom="16.4dp"
                android:textSize="16.5sp"
                android:textColor="#ffffff"
                android:gravity="bottom"
                customfont:fontName="Lato-MediumItalic.ttf"
                android:layout_alignBottom="@+id/storyImage"/>
        </RelativeLayout>
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/storiesFooter"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@id/storiesBody"
        android:layout_marginBottom="20dp"
        android:background="#ffffff"
        android:orientation="horizontal">
        <LinearLayout
            android:id="@+id/storiesLikesLinLayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.3"
            android:orientation="vertical">
            <RelativeLayout
                android:id="@+id/storiesLikesRelLayout"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal">
                <LinearLayout
                    android:id="@+id/storiesLikesLinInRelLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="horizontal">
                    <ImageView
                        android:id="@+id/likesImg"
                        android:layout_width="14.6dp"
                        android:layout_height="13.4dp"
                        android:src="@drawable/ic_story_like"/>
                    <io.newfaces.layout.MyTextView
                        android:id="@+id/noOfLikesForStory"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="15sp"
                        customfont:fontName="Lato-Light.ttf"
                        android:layout_marginLeft="5.6dp"
                        android:text="0 likes">
                    </io.newfaces.layout.MyTextView>
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>
        <View
            android:id="@+id/borderShare1"
            android:layout_width="1.5dp"
            android:layout_height="match_parent"
            android:background="#d8d8d8"/>
        <LinearLayout
            android:id="@+id/storiesCommentsLinLayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.4"
            android:orientation="vertical">
            <RelativeLayout
                android:id="@+id/storiesCommentsRelLayout"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal">
                <LinearLayout
                    android:id="@+id/storiesCommentsLinInRelLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="horizontal">
                    <ImageView
                        android:id="@+id/commentsImg"
                        android:layout_width="14.6dp"
                        android:layout_height="13.4dp"
                        android:src="@drawable/ic_story_comment"/>
                    <io.newfaces.layout.MyTextView
                        android:id="@+id/noOfComments"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="15sp"
                        customfont:fontName="Lato-Light.ttf"
                        android:layout_marginLeft="5.6dp"
                        android:text="0 comments">
                    </io.newfaces.layout.MyTextView>
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>
        <View
            android:id="@+id/borderShare2"
            android:layout_width="1.5dp"
            android:layout_height="match_parent"
            android:background="#d8d8d8"/>
        <LinearLayout
            android:id="@+id/storiesShareLinLayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.3"
            android:orientation="vertical">
            <RelativeLayout
                android:id="@+id/storiesShareRelLayout"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal">
                <LinearLayout
                    android:id="@+id/storiesShareLinInRelLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="horizontal">
                    <ImageView
                        android:id="@+id/shareImg"
                        android:layout_width="14.6dp"
                        android:layout_height="13.4dp"
                        android:src="@drawable/ic_story_share"/>
                    <io.newfaces.layout.MyTextView
                        android:id="@+id/buttonShare"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="15sp"
                        customfont:fontName="Lato-Light.ttf"
                        android:layout_marginLeft="5.6dp"
                        android:text="Share">
                    </io.newfaces.layout.MyTextView>
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>
</LinearLayout>

我想在此选择带有espressostoriesCommentsLinLayoutstoriesBodyOnlyTextLayout

我尝试使用onData(withClild(anyOf(withText(“ mySampleText”)))))并收到错误

android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.

在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1970)

Caused by: java.lang.RuntimeException: No data found matching: has child: (with text: is "royalTreatment") contained values: <[Data: io.newfaces.bo.Story@ad6689a (class: io.newfaces.bo.Story) token: 0, Data: io.newfaces.bo.Story@245a5cb (class: io.newfaces.bo.Story) token: 1, Data: io.newfaces.bo.Story@62da1a8 (class: io.newfaces.bo.Story) token: 2, Data: io.newfaces.bo.Story@89f34c1 (class: io.newfaces.bo.Story) token: 3, Data: io.newfaces.bo.Story@c227466 (class: io.newfaces.bo.Story) token: 4, Data: io.newfaces.bo.Story@706d3a7 (class: io.newfaces.bo.Story) token: 5, Data: io.newfaces.bo.Story@c8f3054 (class: io.newfaces.bo.Story) token: 6, Data: io.newfaces.bo.Story@ea95bfd (class: io.newfaces.bo.Story) token: 7, Data: io.newfaces.bo.Story@ad170f2 (class: io.newfaces.bo.Story) token: 8, Data: io.newfaces.bo.Story@8c30343 (class: io.newfaces.bo.Story) token: 9]>
维亚切斯拉夫·佩达克(Vyacheslav Pedak)

当使用onData语句时,您将使用数据类(如io.newfaces.bo.Story所见),而不是使用Views。因此,您应该定义io.newfaces.bo.StoryonData中的匹配项,然后可以在与该数据相对应的View上执行必要的操作。

像这样的东西:

onData(allOf(is(new BoundedMatcher<Object, Person>(Person.class) {
    @Override
    public void describeTo(Description description) {
    }
    @Override
    protected boolean matchesSafely(Story story) {
        return story.id == 123;
   }
})))

我在这里期望您的Story对象具有一个ID(例如)。

您可以在这里找到更多详细信息

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将自定义适配器添加到活动中以使列表出现在活动中?

来自分类Dev

片段的ViewPager中的Listview适配器-如何获取活动

来自分类Dev

反复用适配器中的第一项填充ListView

来自分类Dev

Android:如何在回收站布局适配器中动态填充片段?

来自分类Dev

LINQ:查找列表中的一项是否出现在字符串数组中

来自分类Dev

如何在片段中声明适配器?

来自分类Dev

如何在回收器适配器中添加片段?

来自分类Dev

如何让 recyclerview 适配器知道存储在 firebase 中的列表现在从另一个活动中为空?

来自分类Dev

从适配器中的片段调用元素

来自分类Dev

从ViewPager中的片段调用适配器

来自分类Dev

从适配器中的片段调用元素

来自分类Dev

从ViewPager中的片段调用适配器

来自分类Dev

在片段中设置适配器

来自分类Dev

如何从Kotlin中的适配器打开活动

来自分类Dev

如何在活动中更新适配器的文本视图

来自分类Dev

如何在适配器中启动活动

来自分类Dev

在适配器中膨胀不同的布局

来自分类Dev

如何从bindViewHolder中更改适配器项资源

来自分类Dev

在适配器中启动活动

来自分类Dev

如何在另一个活动中获取阵列适配器的位置

来自分类Dev

用意式浓缩咖啡在列表中确定适当的项目数

来自分类Dev

如何在不获取空指针异常的情况下从活动片段中获取适配器?

来自分类Dev

如何制作一个RecyclerView适配器以在每行中获取3个arraylist项

来自分类Dev

没有连接适配器;跳过片段中的布局错误

来自分类Dev

在另一个列表中解析命名的JSON时出现“未连接适配器;跳过布局”错误

来自分类Dev

片段活动中我的Listview适配器上的空指针

来自分类Dev

如何在recycleview适配器中设置布局可见性,我的适配器代码是

来自分类Dev

用意式浓缩咖啡测试订单

来自分类Dev

浓缩咖啡测试中的“无法启动活动”

Related 相关文章

  1. 1

    如何将自定义适配器添加到活动中以使列表出现在活动中?

  2. 2

    片段的ViewPager中的Listview适配器-如何获取活动

  3. 3

    反复用适配器中的第一项填充ListView

  4. 4

    Android:如何在回收站布局适配器中动态填充片段?

  5. 5

    LINQ:查找列表中的一项是否出现在字符串数组中

  6. 6

    如何在片段中声明适配器?

  7. 7

    如何在回收器适配器中添加片段?

  8. 8

    如何让 recyclerview 适配器知道存储在 firebase 中的列表现在从另一个活动中为空?

  9. 9

    从适配器中的片段调用元素

  10. 10

    从ViewPager中的片段调用适配器

  11. 11

    从适配器中的片段调用元素

  12. 12

    从ViewPager中的片段调用适配器

  13. 13

    在片段中设置适配器

  14. 14

    如何从Kotlin中的适配器打开活动

  15. 15

    如何在活动中更新适配器的文本视图

  16. 16

    如何在适配器中启动活动

  17. 17

    在适配器中膨胀不同的布局

  18. 18

    如何从bindViewHolder中更改适配器项资源

  19. 19

    在适配器中启动活动

  20. 20

    如何在另一个活动中获取阵列适配器的位置

  21. 21

    用意式浓缩咖啡在列表中确定适当的项目数

  22. 22

    如何在不获取空指针异常的情况下从活动片段中获取适配器?

  23. 23

    如何制作一个RecyclerView适配器以在每行中获取3个arraylist项

  24. 24

    没有连接适配器;跳过片段中的布局错误

  25. 25

    在另一个列表中解析命名的JSON时出现“未连接适配器;跳过布局”错误

  26. 26

    片段活动中我的Listview适配器上的空指针

  27. 27

    如何在recycleview适配器中设置布局可见性,我的适配器代码是

  28. 28

    用意式浓缩咖啡测试订单

  29. 29

    浓缩咖啡测试中的“无法启动活动”

热门标签

归档