이 질문에 대한 답변 (here, here, and here)을 조사했는데 제안 된 솔루션 중 아무 것도 작동하지 않았습니다. 내 문제는 내 RecyclerView 목록 항목이 표시되지 않는 것입니다. 나는 MessengerRecyclerAdapter, onCreateViewHolder, onBindViewHolder 및 getItemCount에 중단 점을 설정했으며 첫 번째 호출 만 호출합니다. 중단 점에서 나는 식 계산기를 입력하고 RecyclerView가 getItemCount를 호출하지 않음
MessengerRecyclerAdapter.getItemCount();
을 실행 그리고 (20)의 예상 답을받은 RecyclerView 자체가 아래의 스크린 샷에 의해 입증 된 바와 같이 의도 된 컨텐츠 영역을 차지했습니다 동안 (내가 할 수있는 RecyclerView 마젠타을 설정 점유하는 공간을 강조 표시하십시오).
내 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의 방향을 설정 한 확인하고이 개 가장 일반적인 솔루션했다 레이아웃 매니저를 설정할 수있다. 나는 정말로 다음에 무엇을 시도 해야할지에 대해 상실감을 느낀다. 그래서 어떤 도움도 인정 될 것이다.
가) (onViewCreated 대신 onCreateView (방법을 당신의 코드를 작성 작업의 스크린 샷입니다 당신이해야 부풀려진 뷰만 반환하면 나머지 코드는 onViewCreated에 있어야합니다. –
'fragment_messenger_cell.xml'을 보여주고'mRecyclerView.setHasFixedSize (true);를 시도하십시오. –