Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 垂直回收视图中的水平回收视图不工作,onCreateViewHolder从未调用_Android_Android Recyclerview - Fatal编程技术网

Android 垂直回收视图中的水平回收视图不工作,onCreateViewHolder从未调用

Android 垂直回收视图中的水平回收视图不工作,onCreateViewHolder从未调用,android,android-recyclerview,Android,Android Recyclerview,我像facebook一样展示帖子,在每个帖子中都有一个包含多个图片的图像滑块,在我的列表中,第一个项目与其他项目不同,因此我使用的是异构回收视图,这里我所做的请查看我的代码 if (commentList.get(position).getAttachment() != null && !commentList.get(position).getAttachment().equals("")) { List<String> imageU

我像facebook一样展示帖子,在每个帖子中都有一个包含多个图片的图像滑块,在我的列表中,第一个项目与其他项目不同,因此我使用的是异构回收视图,这里我所做的请查看我的代码

    if (commentList.get(position).getAttachment() != null && !commentList.get(position).getAttachment().equals(""))
    {
        List<String> imageUrl = new ArrayList<>();
        imageUrl.add(commentList.get(position).getAttachment());
        holder.getImageSliderCommentRecycler().setAdapter(new ImageSliderAdapter(context, imageUrl, new ImageSlideItemListener()
        {
            @Override
            public void imageClicked(int position)
            {
                List<String> imageUrl = new ArrayList<>();
                imageUrl.add(commentList.get(holder.getAdapterPosition()-1).getAttachment());
                listener.showImage(imageUrl, position);
            }
        }));

        holder.getImageSliderCommentRecycler().setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
    }
    else holder.getImageSliderCommentRecycler().setVisibility(View.GONE);
}

代码非常复杂,所以我只发布块,因为其他一切都很好。。。。我一天前刚刚添加的这个图像滑块,当时效果不错,但现在不是


任何帮助都将不胜感激……提前感谢

经过两天的努力,我终于找到了问题所在。。。。问题是XML,我对两个不同的RecyclerViews使用相同的Id,所以它总是找到第一个RecyclerViews并设置其适配器,而忽略了第二个…我没有意识到这一点的真正原因是编译器,因为这两个RecyclerViews位于父相对布局容器中,它们不是兄弟。此外,我还通过使用“include”标记添加了第一个recyclerview

下面是我的XML的完整外观

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_post_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="controllers.marham.marhammed.activities.DetailPostActivity">

<RelativeLayout
    android:id="@+id/topcolor_red"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:background="@color/light_blue">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/forum"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/white" />

    <ImageButton
        android:id="@+id/backBtn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:background="@color/light_blue"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:src="@drawable/backicon"/>


</RelativeLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/post_detail_activity_recyclerview"
    android:layout_below="@+id/topcolor_red"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ScrollView
    android:id="@+id/post_detail_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone">

    <include
        layout="@layout/layout_post_detail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</ScrollView>

</RelativeLayout>

下面是代码的其余部分

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/activity_post_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/off_white">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="5dp"
    android:padding="5dp"
    app:cardUseCompatPadding="true"
    card_view:cardCornerRadius="5dp"
    card_view:cardElevation="5dp"
    card_view:cardPreventCornerOverlap="true"
    card_view:cardUseCompatPadding="true"
    card_view:contentPadding="5dp">

    <RelativeLayout
        android:id="@+id/post_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">

        <Button
            android:id="@+id/post_detail_activity_ask_ques_button"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="20dp"


        android:background="@drawable/draw_body_red_button_circular_corners"
            android:text="Ask Free Question"
            android:textColor="@color/white"
            android:visibility="gone" />

        <ImageView
            android:id="@+id/speciality_icon_imageview"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginTop="40dp" />

        <TextView
            android:id="@+id/post_title_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/post_detail_activity_ask_ques_button"
            android:layout_marginEnd="30dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="30dp"
            android:layout_marginStart="5dp"
            android:layout_marginTop="30dp"
            android:layout_toEndOf="@id/speciality_icon_imageview"
            android:layout_toRightOf="@id/speciality_icon_imageview"
            android:maxLines="1"
            android:text="Title Of Problem"
            android:textColor="@color/blue"
            android:textSize="22sp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/delete_post_imageview"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/delete_icon" />

        <TextView
            android:id="@+id/patient_detail_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/post_title_textview"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:text="Patient Detail"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/post_description_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/patient_detail_textview"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:lineSpacingExtra="8dp"
            android:text="Some Description"
            android:textSize="16sp" />

        <RelativeLayout
            android:id="@+id/post_photo_relative_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/post_description_textview"
            android:layout_marginEnd="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginStart="20dp"
            android:layout_marginTop="35dp">

            <android.support.v7.widget.RecyclerView

    android:id="@+id/about_doctor_fragment_doctor_photos_fragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"

    app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

        </RelativeLayout>


        <TextView
            android:id="@+id/post_time_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/post_photo_relative_layout"
            android:layout_marginTop="25dp"
            android:text="Yesterday at 12:06 AM"
            android:textColor="@color/blue"
            android:textSize="13sp"
            android:textStyle="bold" />

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/post_time_textview"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/line_shape" />


        <TextView
            android:id="@+id/post_number_of_answers_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/view"
            android:layout_marginBottom="20dp"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:text="n Answers"
            android:textColor="@color/red"
            android:textStyle="bold"
            android:visibility="invisible" />


        <ImageView
            android:id="@+id/share_post_imageview"
            android:layout_width="25dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/view"
            android:layout_marginBottom="20dp"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/share_icon_red"
            android:textColor="@color/red" />

        <Button
            android:id="@+id/post_detail_activity_post_answer_button"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignEnd="@+id/share_post_imageview"
            android:layout_alignLeft="@+id/post_number_of_answers_textview"
            android:layout_alignRight="@+id/share_post_imageview"
            android:layout_alignStart="@+id/post_number_of_answers_textview"
            android:layout_below="@+id/post_number_of_answers_textview"
            android:layout_marginBottom="20dp"


     android:background="@drawable/draw_body_red_button_circular_corners"
            android:text="@string/post_answer"
            android:textAllCaps="false"
            android:textSize="16sp"
            android:textStyle="bold"
            android:textColor="@color/white" />

    </RelativeLayout>
</android.support.v7.widget.CardView>


我发布这篇文章是为了让其他人可以节省一些时间。感谢您阅读……:)

我已经阅读了几乎所有的解决方案,但没有一个适合我。。。因此,在编辑或引用副本之前,请至少询问一次……添加适配器/持有者代码和活动please@JonathanAste谢谢你的回复。。。。。完整的代码太长,请粘贴在此处。。。。我正在第一个代码块中设置适配器…我看不出您在哪里为适配器设置数据。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_post_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="controllers.marham.marhammed.activities.DetailPostActivity">

<RelativeLayout
    android:id="@+id/topcolor_red"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:background="@color/light_blue">

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/forum"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/white" />

    <ImageButton
        android:id="@+id/backBtn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        android:background="@color/light_blue"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:src="@drawable/backicon"/>


</RelativeLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/post_detail_activity_recyclerview"
    android:layout_below="@+id/topcolor_red"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ScrollView
    android:id="@+id/post_detail_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone">

    <include
        layout="@layout/layout_post_detail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</ScrollView>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/activity_post_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/off_white">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="5dp"
    android:padding="5dp"
    app:cardUseCompatPadding="true"
    card_view:cardCornerRadius="5dp"
    card_view:cardElevation="5dp"
    card_view:cardPreventCornerOverlap="true"
    card_view:cardUseCompatPadding="true"
    card_view:contentPadding="5dp">

    <RelativeLayout
        android:id="@+id/post_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white">

        <Button
            android:id="@+id/post_detail_activity_ask_ques_button"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="20dp"


        android:background="@drawable/draw_body_red_button_circular_corners"
            android:text="Ask Free Question"
            android:textColor="@color/white"
            android:visibility="gone" />

        <ImageView
            android:id="@+id/speciality_icon_imageview"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginTop="40dp" />

        <TextView
            android:id="@+id/post_title_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/post_detail_activity_ask_ques_button"
            android:layout_marginEnd="30dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="30dp"
            android:layout_marginStart="5dp"
            android:layout_marginTop="30dp"
            android:layout_toEndOf="@id/speciality_icon_imageview"
            android:layout_toRightOf="@id/speciality_icon_imageview"
            android:maxLines="1"
            android:text="Title Of Problem"
            android:textColor="@color/blue"
            android:textSize="22sp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/delete_post_imageview"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="30dp"
            android:background="@drawable/delete_icon" />

        <TextView
            android:id="@+id/patient_detail_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/post_title_textview"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:text="Patient Detail"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/post_description_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/patient_detail_textview"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:lineSpacingExtra="8dp"
            android:text="Some Description"
            android:textSize="16sp" />

        <RelativeLayout
            android:id="@+id/post_photo_relative_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/post_description_textview"
            android:layout_marginEnd="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginStart="20dp"
            android:layout_marginTop="35dp">

            <android.support.v7.widget.RecyclerView

    android:id="@+id/about_doctor_fragment_doctor_photos_fragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"

    app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

        </RelativeLayout>


        <TextView
            android:id="@+id/post_time_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/post_photo_relative_layout"
            android:layout_marginTop="25dp"
            android:text="Yesterday at 12:06 AM"
            android:textColor="@color/blue"
            android:textSize="13sp"
            android:textStyle="bold" />

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/post_time_textview"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/line_shape" />


        <TextView
            android:id="@+id/post_number_of_answers_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/post_title_textview"
            android:layout_alignStart="@+id/post_title_textview"
            android:layout_below="@+id/view"
            android:layout_marginBottom="20dp"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:text="n Answers"
            android:textColor="@color/red"
            android:textStyle="bold"
            android:visibility="invisible" />


        <ImageView
            android:id="@+id/share_post_imageview"
            android:layout_width="25dp"
            android:layout_height="20dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/view"
            android:layout_marginBottom="20dp"
            android:layout_marginEnd="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/share_icon_red"
            android:textColor="@color/red" />

        <Button
            android:id="@+id/post_detail_activity_post_answer_button"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignEnd="@+id/share_post_imageview"
            android:layout_alignLeft="@+id/post_number_of_answers_textview"
            android:layout_alignRight="@+id/share_post_imageview"
            android:layout_alignStart="@+id/post_number_of_answers_textview"
            android:layout_below="@+id/post_number_of_answers_textview"
            android:layout_marginBottom="20dp"


     android:background="@drawable/draw_body_red_button_circular_corners"
            android:text="@string/post_answer"
            android:textAllCaps="false"
            android:textSize="16sp"
            android:textStyle="bold"
            android:textColor="@color/white" />

    </RelativeLayout>
</android.support.v7.widget.CardView>