Solution in Recyclerview adapter call notifydatasetchanged is invalid _recyclerview

Source: Internet
Author: User

The layout of the sliding display of multiple fragment for my project with Tablayout+viewpage

The first one to use the Recyclerview, found Recyclerviewadapter call notifydatasetchanged when nothing came out, because the other several fragment are not listed, So you've debugged the recyclerviewadapter in this fragment, and the following is the method that you follow to get the data.

private void SetData () {
if (adapter==null) {
Adapter = new Popularitytendadapter (mcontext,datalists);
Recyclerview.setadapter (Adapter);//recyclerview Settings Adapter
Adapter.setonitemclicklistener (New Onrecyclerviewitemclicklistener () {
@Override
public void Onitemclick (view view, int position) {
Toast.maketext (Mcontext, "clicked" +position, Toast.length_short). Show ();

}
});
Recyclerview.setnestedscrollingenabled (FALSE);
}else{
Refreshing data
Adapter.notifydatasetchanged ()//
}
}

The initial load is OK, but when you slide back from the other fragment, the content is not displayed, the adapter.notifydatasetchanged () is called, but there is no display.

On the Internet read this for the brothers analysis of the http://blog.csdn.net/csdn_lqr/article/details/61925004, selected the second kind, In fact, and ListView in the GetView in the Contentview price to determine whether the operation is empty, the difference is not to avoid repeating the view, but related to the fragment life cycle, the data datalists is unchanged, But the Recyclerview changed.

So it's OK to judge in Oncreateview whether the root view price is empty.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.