प्रदर्शित नहीं कर रहा है मेरे पास एक RecyclerView है जो किसी भी आइटम को प्रदर्शित नहीं कर रहा है। प्रारंभ में यह खाली है, लेकिन बाद में मैं आइटम जोड़ता हूं और सूचित करता हूंडेटाडेटेड()। getItemCount() को कॉल किया जाता है और 25 देता है, पर बाइंडव्यूहोल्डर को 3 बार बुलाया जाता है और दृश्य को सही तरीके से सेट करता है।रीसाइक्लर
public AlbumListAdapter(FacebookActivity activity, long pageId, OnItemClickListener listener){
this.listener = listener;
this.inflater = LayoutInflater.from(activity);
this.service = new PagedGraphService<Album>(String.format("https://graph.facebook.com/%d/albums", pageId),
new PagedGraphService.ServiceUpdateListener() {
@Override
public void dataUpdated() {
notifyDataSetChanged();
}
@Override
public void endReached() {
}
},
new TypeToken<PagedGraphService.GraphResponse<Album>>(){}.getType());
}
@Override
public AlbumHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
return new AlbumHolder(inflater.inflate(R.layout.photo_album_list_card, viewGroup, false));
}
@Override
public void onBindViewHolder(AlbumHolder viewHolder, int i) {
viewHolder.setAlbum(service.get(i));
}
@Override
public int getItemCount() {
return service.getLoadedCount();
}
इसका सारांश। सेवा में एल्बमों की एक सूची है और डेटा अद्यतन() और endReached() को कॉल करके परिवर्तनों के एडाप्टर को सूचित करता है।
अधिक कोड:
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
RecyclerView view = (RecyclerView) inflater.inflate(R.layout.recycler, container, false);
view.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));
view.setHasFixedSize(false);
AlbumListAdapter adapter = new AlbumListAdapter(activity, FacebookActivity.PSM_PAGE_ID, this);
view.setAdapter(adapter);
return view;
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
इससे भी अधिक कोड:
गतिविधि लेआउट
<?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">
<include layout="@layout/toolbar"/>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
सूची आइटम लेआउट:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/album_list_title"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v7.widget.CardView>
सूची लेआउट:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
मैं अब कुछ घंटों के लिए कोड poking किया गया है और मुझे पता नहीं क्यों यह काम नहीं करता
ए) आपको हमें अपना कोड दिखाना है; बी) RecyclerView पर 'notifyDatasetChanged()' को कॉल करना कुशल नहीं है और इस प्रकार – reVerse
ठंडा नहीं है एडाप्टर की अधिसूचनाडेटासेट चेंज को डेटा प्राप्त होने पर कॉल किया जाता है। – DariusL
यह मूल रूप से मेरा उल्लेख है - [डॉक्स] (https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html#notifyDataSetChanged%28%29) का उद्धरण: 'यदि आप हैं एक एडाप्टर लिखना यदि आप कर सकते हैं तो अधिक विशिष्ट परिवर्तन घटनाओं का उपयोग करने के लिए यह हमेशा अधिक कुशल होगा। अंतिम उपाय के रूप मेंडेटाडेट चेंज() को सूचित करें। – reVerse