Load a Listview into a Fragment from a Fragment

0

I'm in the following situation:

I have a TabBar with 2 Fragments (ProductFragment and CartFragment). Within the ProductFragment I have a ListView with an add button that fires, adds an item in a ListView inside the CartFragment, and also changes 3 different TextViews with the sums of values of that same datasource that loads the list.

How can I reload the CartFragment so I can change my data? At the moment, it only loads if I exit the TabBar and back. Even using the notifyDataSetChanged ();

    
asked by anonymous 10.04.2017 / 17:11

1 answer

0

There are Libs for this work but at the moment I do not remember the names, other two forms are with Intents and Intents filters or the simpler way I will illustrate below.

In the CartFragment class, create the notifyMudancaCarrinho method ();

public void notificarMudancaCarrinho(){
    //aqui sua logica para dar o refresh
    //ex:
    adapter.notifyDataSetChanged();
}

In the Activity class, create the notifyMudancaCarrinho method ();

public void notificarMudancaCarrinho(){
    carrinhoFragment.notificarMudancaCarrinho();
}

In the ProductFragment where you add the product in the cart simply add the following line.

((SuaActivity) getActivity()).notificarMudancaCarrinho();
    
10.04.2017 / 18:34