Load a Listview into a Fragment from a Fragment

Asked

Viewed 315 times

0

I’m in the following situation:

I have a Tabbar with 2 Fragments (Productofragment and Carrinhofragment). Inside the Productofragment I have a Listview with an add button that triggered, adds an item in a Listview inside the Cartfragment and also changes 3 different Textview with the summations of values of the same datasource that loads the list.

How do I get him to reload the Cartwheel fragment so I can change my data? At the moment, it only loads if I leave Tabbar and come back. Even using notifyDataSetChanged();

  • Put your source code so I can give a better answer.

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 is Intents Filters or the simplest way I will exemplify below.

In the Cartfragment class create the method to notify();

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

In the Activity class create the method to notify();

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

On the Productofragment where you make the addition of the product in the cart just add the following line.

((SuaActivity) getActivity()).notificarMudancaCarrinho();

Browser other questions tagged

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