स्पर्श किए जाने तक कुछ भी नहीं दिखाता है, मैं अपने ऐप में समर्थन RecyclerView का उपयोग कर रहा हूं, और मुझे सबसे विचित्र चीज़ दिखाई देती है। जब तक मैं स्क्रॉल करने के लिए स्पर्श नहीं करता तब तक यह कोई आइटम प्रदर्शित नहीं करता है। फिर, अचानक, RecyclerView खुद को populates। मैंने सत्यापित किया है कि एडाप्टर का समर्थन करने वाली सूची पॉप्युलेट की गई है, और उस पर CreatViewHolder और OnBindViewHolder को टच ईवेंट तक कभी नहीं बुलाया जाता है।समर्थन पुनर्चक्रण दृश्य
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
<android.support.v7.widget.RecyclerView
android:id="@+id/lv_inbox"
android:layout_width="match_parent"
android:layout_height="match_parent"
></android.support.v7.widget.RecyclerView>
</RelativeLayout>
मैं recyclerview उपयोग कर रहा हूँ:
public class InboxAdapter extends RecyclerView.Adapter<InboxAdapter.ViewHolder> {
List<Conversation> mConversations; //initialized in contructor
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = mInflater.inflate(R.layout.inbox_item, parent, false);
ViewHolder holder = new ViewHolder(v);
Log.d(LOG_TAG, "oncreateviewholder : " + viewType); //never called when I first bind the adapter
return holder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final Conversation item = mConversations.get(position);
Log.d(LOG_TAG, "binding " + position);
...
}
@Override
public int getItemCount() {
Log.d(LOG_TAG, "item count: " + mConversations.size());
return mConversations.size();
}
/**
* Empties out the whole and optionally notifies
*/
public void clear(boolean notify) {
mConversations.clear();
if (notify) {
notifyDataSetChanged();
}
}
public void addAll(List<Conversation> conversations) {
mConversations.addAll(conversations);
notifyDataSetChanged();
}
}
यहाँ लेआउट फ़ाइल है:
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
Drawable divider = new ColorDrawable(ProfileInfo.getCurrentProfileColor());
mInboxList.addItemDecoration(new DividerItemDecoration(getActivity(), divider, false));
mInboxList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
mInboxList.setAdapter(new InboxAdapter(getActivity(), new ArrayList<Conversation>()));
new AsyncTask<Void, Void, List<Conversation>{
public List<Conversation> doInBackground(...){
//load the conversations
return conversations;
}
public void onPostExecute(List<Conversation> conversations){
((InboxAdapter) mInboxList.getAdapter()).clear(false);
((InboxAdapter) mInboxList.getAdapter()).addAll(conversations);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
यहाँ मेरी एडाप्टर के एक सार है:
यहाँ कैसे मैं recyclerview की स्थापना की है -v7: 21.0.3 संस्करण 4.4.4 के साथ एक मोटो एक्स पर चल रहा है।
संपादित करें:
if (mInboxList.getAdapter().getItemCount() > 0) {
mInboxList.smoothScrollToPosition(0);
}
आप समर्थन लाइब्रेरी 22.2.1 की कोशिश की है? यह कई कीड़े तय की। –
आपका 'EDIT' उत्तर होना चाहिए :) –
वाह ... क्या यह एंड्रॉइड बग है? यह अभी भी – Zyoo