0

이 질문에 대한 답변 (here, here, and here)을 조사했는데 제안 된 솔루션 중 아무 것도 작동하지 않았습니다. 내 문제는 내 RecyclerView 목록 항목이 표시되지 않는 것입니다. 나는 MessengerRecyclerAdapter, onCreateViewHolder, onBindViewHolder 및 getItemCount에 중단 점을 설정했으며 첫 번째 호출 만 호출합니다. 중단 점에서 나는 식 계산기를 입력하고 RecyclerView가 getItemCount를 호출하지 않음

MessengerRecyclerAdapter.getItemCount(); 

을 실행 그리고 (20)의 예상 답을받은 RecyclerView 자체가 아래의 스크린 샷에 의해 입증 된 바와 같이 의도 된 컨텐츠 영역을 차지했습니다 동안 (내가 할 수있는 RecyclerView 마젠타을 설정 점유하는 공간을 강조 표시하십시오).

RecyclerView location

내 RecyclerView의 XML 코드는 다음과 같습니다 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/thread_list" 
    android:background="@color/colorAccent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:name="com.jypsee.jypseeconnect.orgPicker.MessengerListFragment" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layoutManager="LinearLayoutManager" 
    tools:context="com.jypsee.jypseeconnect.orgPicker.MessengerListFragment" 
    tools:listitem="@layout/fragment_messenger_cell"/> 

</LinearLayout> 

내 RecyclerView 셀 XML :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

<TextView 
    android:id="@+id/id" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/text_margin" 
    android:textAppearance="?attr/textAppearanceListItem" 
    android:textColor="@color/blueText"/> 

<TextView 
    android:id="@+id/content" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/text_margin" 
    android:textAppearance="?attr/textAppearanceListItem" 
    android:textColor="@color/darkText"/> 
</LinearLayout> 

내 ListFragment 클래스 :

@Override 
public View onCreateView(LayoutInflater inflater, 
         ViewGroup container, 
         Bundle savedInstanceState) { 

    List<DummyContent.DummyItem> items = new ArrayList<>(); 
    for (Integer i = 0; i<20; i++){ 
     DummyContent.DummyItem item = new DummyContent.DummyItem(i.toString(),"Content","Details"); 
     items.add(item); 
    } 

    View view = inflater.inflate(R.layout.fragment_messenger_list, container, false); 
    mRecyclerView = (RecyclerView) view.findViewById(R.id.thread_list); 
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 
    mRecyclerAdapter = new MessengerThreadRecyclerAdapter(items, mListener); 
    mRecyclerView.setAdapter(mRecyclerAdapter); 
    mRecyclerAdapter.notifyDataSetChanged(); 
    return view; 
} 

내 어댑터 클래스 :

public class MessengerRecyclerAdapter 
    extends RecyclerView.Adapter<MessengerRecyclerAdapter.MessageThreadHolder>{ 

private final List<DummyItem> mValues; 
private final RecyclerViewClickListener mListener; 

public MessengerRecyclerAdapter(List<DummyItem> items, RecyclerViewClickListener listener) { 
    mValues = items; 
    mListener = listener; 
} 

@Override 
public MessageThreadHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view = LayoutInflater.from(parent.getContext()) 
      .inflate(R.layout.fragment_messenger_cell, parent, false); 
    return new MessageThreadHolder(view); 
} 

@Override 
public void onBindViewHolder(final MessageThreadHolder holder, final int position) { 
    holder.mItem = mValues.get(position); 
    holder.mIdView.setText(mValues.get(position).id); 
    holder.mContentView.setText(mValues.get(position).content); 
    holder.mView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (mListener != null) { 
       mListener.recyclerViewListClicked(v, position); 
      } 
     } 
    }); 
} 

@Override 
public int getItemCount() { 
    return mValues.size(); 
} 

public class MessageThreadHolder extends RecyclerView.ViewHolder { 
    public final View mView; 
    public final TextView mIdView; 
    public final TextView mContentView; 
    public DummyItem mItem; 

    public MessageThreadHolder(View view) { 
     super(view); 
     mView = view; 
     mIdView = (TextView) view.findViewById(R.id.id); 
     mContentView = (TextView) view.findViewById(R.id.content); 
    } 
} 

}

당신은 내가 수직에있는 LinearLayout의 방향을 설정 한 확인하고이 개 가장 일반적인 솔루션했다 레이아웃 매니저를 설정할 수있다. 나는 정말로 다음에 무엇을 시도 해야할지에 대해 상실감을 느낀다. 그래서 어떤 도움도 인정 될 것이다.

+0

가) (onViewCreated 대신 onCreateView (방법을 당신의 코드를 작성 작업의 스크린 샷입니다 당신이해야 부풀려진 뷰만 반환하면 나머지 코드는 onViewCreated에 있어야합니다. –

+0

'fragment_messenger_cell.xml'을 보여주고'mRecyclerView.setHasFixedSize (true);를 시도하십시오. –

답변

1

이전의 답변에서 편집했듯이. 문제는 XML에 있습니다. 그 이유는 다음과 같습니다. 조각 태그 대신 include 태그를 사용하여 조각을 추가하려고 했으므로 각 조각 클래스가 작업에 추가되는 조각 레이아웃에 결코 호출되지 않았습니다. 다음은 단편을 올바르게 추가하는 데 필요한 코드입니다.

<fragment 
     android:id="@+id/message_thread" 
     android:name="com.jypsee.jypseeconnect.orgPicker.MessengerThreadListFragment" 
     layout="@layout/fragment_messengerthread_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:layout="@layout/fragment_messengerthread_list" /> 

그리고 당신의 조각 레이아웃 다음은이

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".orgPicker.MessengerThreadListFragment"> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/thread_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

같아야는 onCreateView에서) enter image description here

+1

@JamesJordanTaylor 가능한 경우 이메일로 프로젝트를 보내주십시오. 내 이메일 ID는 [email protected]입니다. –

+0

@JamesJordanTaylor Lemme이 확인하고 다시 연락 드리겠습니다. –

+0

@JamesJordanTaylor 저는 제 대답을 업데이트하고 이메일을 보냈습니다. 확인해주십시오 –

관련 문제