2017-03-31 60 views
0

我显示职位就像facebook,并在每个职位有一个图像滑块与多个图像,在我的清单第一项是不同的,然后其他项目,所以我是使用多相RecyclerView,在这里我做了什么,请参阅我的代码,水平RecyclerView里面垂直recyclerview不工作,onCreateViewHolder从来没有打电话

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); 

如果条件执行,但imageSliderAdapter永远不会调用oncreateViewHolder或其他任何东西...这里是XML代码,请参阅,

 <RelativeLayout 
      android:id="@+id/post_photo_relative_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/comment_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> 

这里是我的adapterV iewHolder ...

public class CommentViewHolder extends RecyclerView.ViewHolder 
{ 
private ImageView commentProfileImage; 
private TextView commentName; 
private TextView commentSpeciality; 
private ImageView commentDeleteIcon; 
private Button bookAppointmentButton; 
private TextView commentDescription; 
private TextView commentDateTime; 
private ImageView commentLikeIcon; 
private TextView commentLikeCounter; 
private Button replyButton; 
private RecyclerView replyRecyclerView; 
private RecyclerView imageSliderCommentRecycler; 

public CommentViewHolder(View itemView) 
{ 
    super(itemView); 

    commentProfileImage = (ImageView) itemView.findViewById(R.id.photo_imageview); 
    commentName = (TextView) itemView.findViewById(R.id.user_name_textview); 
    commentSpeciality = (TextView) itemView.findViewById(R.id.user_speciality_textview); 
    commentDeleteIcon = (ImageView) itemView.findViewById(R.id.delete_comment_imageview); 
    bookAppointmentButton = (Button) itemView.findViewById(R.id.book_appointment_button); 
    commentDescription = (TextView) itemView.findViewById(R.id.comment_textview); 
    commentDateTime = (TextView) itemView.findViewById(R.id.comment_time_textview); 
    commentLikeIcon = (ImageView) itemView.findViewById(R.id.like_imageview); 
    commentLikeCounter = (TextView) itemView.findViewById(R.id.likes_count_textview); 
    replyButton = (Button) itemView.findViewById(R.id.reply_button); 
    replyRecyclerView = (RecyclerView) itemView.findViewById(R.id.replies_recyclerview); 

    imageSliderCommentRecycler = (RecyclerView) itemView.findViewById(R.id.about_doctor_fragment_doctor_photos_fragment); 
} 

public ImageView getCommentProfileImage() 
{ 
    return commentProfileImage; 
} 

public TextView getCommentName() 
{ 
    return commentName; 
} 

public TextView getCommentSpeciality() 
{ 
    return commentSpeciality; 
} 

public ImageView getCommentDeleteIcon() 
{ 
    return commentDeleteIcon; 
} 

public Button getBookAppointmentButton() 
{ 
    return bookAppointmentButton; 
} 

public TextView getCommentDescription() 
{ 
    return commentDescription; 
} 

public TextView getCommentDateTime() 
{ 
    return commentDateTime; 
} 

public ImageView getCommentLikeIcon() 
{ 
    return commentLikeIcon; 
} 

public TextView getCommentLikeCounter() 
{ 
    return commentLikeCounter; 
} 

public Button getReplyButton() 
{ 
    return replyButton; 
} 

public RecyclerView getReplyRecyclerView() 
{ 
    return replyRecyclerView; 
} 

public RecyclerView getImageSliderCommentRecycler() 
{ 
    return imageSliderCommentRecycler; 
} 

}

代码是非常复杂的,因此我张贴只是块,因为一切在一天前工作正常....这个图像滑块我刚才说,在那个时候它工作正常,但现在不是......

任何帮助将感激...在此先感谢

+0

我已经经历了几乎所有的解决方案,但没有为我工作...所以请至少要求在编辑或提交作为重复之前一次.... – Najam

+0

添加您的适配器/持有人代码和你的活动请 –

+0

@JonathanAste谢谢你的回复.....完整的代码太冗长太粘贴在这里....我设置适配器在第一个代码块.... – Najam

回答

0

2天之后的斗争,我终于找出了问题....问题是在使用XML时,我使用了两个不同的RecyclerViews的相同Id,因此它总能找到fir st recyclerview并设置它的适配器,并忽略第二个......为什么我没有意识到这两个编译器的真正原因,因为这两个recyclerviews在父级相对布局容器中,这些不是兄弟姐妹。此外,我还通过使用“包含”标签添加了第一个回收站视图。

这里是我的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> 

我张贴这种从而使他人否则可以节省一些时间。感谢您的阅读... :)

相关问题