Update recyclerview from another fragment, in the same viewpager

Asked

Viewed 317 times

0

I have a viewpager that contains 3 fragments, one for transactions performed,one for transactions canceled and one for open transactions. Each fragment has a recyclerview for displaying transactions and also, each fragment has a swiperefreshlayout so that the user can get the latest information from the server. My doubt is the following: How do I update fragment list 1 and also fragment list 2 and 3 if necessary ?

Ex: when updating the fragment of open transactions, and verify that the arrayList has less elements, logically the transaction that was open, went to the fragment of transactions in canceled or executed. Assuming there has been this modification in the arrayList, I would also like to update fragment 2 and 3 if necessary.

PS: both are in the same viewpager, already tried via interface and could not.

1 answer

0


Try to do so, let’s assume that this in the open transaction fragment and will update the transaction fragment performed. In the transaction fragment performed you make an upgrade method

    private void updateFragment() {

    SeuFragmentTransacaoRealizada fragment =
            (SeuFragmentTransacaoRealizada) getChildFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + posicaoTab);

    if (fragment != null) {

        if (fragment.getView() != null) {

            fragment.atualizarAdapter();
        }
    }
}
  • hello, I followed your line of thought and it worked, however I had to make some changes, the getChildFragmentManager() method was changed to getFragmentManager() and to update the Dapter() worked, I had to implement an interface in which I expected a result of updateFragment(). Vlw

  • I figured I’d do it in the fragment so I switched to getChildFragmentManager(). But I’m glad it worked out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.