Forum Xamarin.Android

recycle view does not update properly

ali.z75ali.z75 GBMember ✭✭
edited July 2017 in Xamarin.Android

hi guys i am struggling 2 days with a recycle view i have a fragment include a recycle view i have a dialog fragment in this fragment and i want when dialog dissmissed recycle view update

this is ovvrerid on dissmiss method in dialog fragment

    somefragment fragment = new somefragment ();
    var trance=Activity.SupportFragmentManager.BeginTransaction();
    trance.Detach(fragment);
    trance.Attach(fragment);
    trance.Commit();

after that i get new data in onstart and give it to adapter again and when i check with break point every thing is fine but still recycle dose not update

`list = await DownloadDataFromServer<List>(uri + Handel.CurrentCityId);

    myAdapter = new RecyclerAdapter(list);
    myRecyclerView.SetAdapter(myAdapter);
      myAdapter.NotifyDataSetChanged();`

Answers

  • MizanurRahman.0834MizanurRahman.0834 USMember ✭✭

    You can create a Task which can help you to update recyclerView every 5 seconds:

    void UpdateData()
    {
    Task.Delay(5000).ContinueWith(t =>
    {
    adapter.NotifyDataSetChanged();
    UpdateData(); //This is for repeate every 5s.
    }, TaskScheduler.FromCurrentSynchronizationContext());
    }

  • cwphillicwphilli USMember ✭✭✭

    @ali.z75 said:
    hi guys i am struggling 2 days with a recycle view i have a fragment include a recycle view i have a dialog fragment in this fragment and i want when dialog dissmissed recycle view update

    this is ovvrerid on dissmiss method in dialog fragment

        somefragment fragment = new somefragment ();
        var trance=Activity.SupportFragmentManager.BeginTransaction();
        trance.Detach(fragment);
        trance.Attach(fragment);
        trance.Commit();
    

    after that i get new data in onstart and give it to adapter again and when i check with break point every thing is fine but still recycle dose not update

    `list = await DownloadDataFromServer<List>(uri + Handel.CurrentCityId);

        myAdapter = new RecyclerAdapter(list);
        myRecyclerView.SetAdapter(myAdapter);
          myAdapter.NotifyDataSetChanged();`
    

    Post your full adapter and view code so that we might help you identify the issue.

    @MizanurRahman.0834 said:
    You can create a Task which can help you to update recyclerView every 5 seconds:

    void UpdateData()
    {
    Task.Delay(5000).ContinueWith(t =>
    {
    adapter.NotifyDataSetChanged();
    UpdateData(); //This is for repeate every 5s.
    }, TaskScheduler.FromCurrentSynchronizationContext());
    }

    Don't do that. Update the view when it has changed.

Sign In or Register to comment.