0

I have the rather specific final List<PieEntry> entries = new ArrayList<>(); (PieEntry is of MPAndroidChart) and I want to pass it to another fragment where it is then diplayed in a chart. I have tried a number of ways like parsing it, but everytime I run the application the piechart seems to have no data to fill itself. (Maybe I didn't do it correctly because the explanation wasn't in depth enough for me).

I backwards tested it, so everything up until the array is fine, for example I can draw the chart in the first fragment and everything works.

Maybe I left some details out, or maybe I am going in the completely wrong direction?

Eldelshell
  • 6,683
  • 7
  • 44
  • 63
Niklas Daute
  • 75
  • 1
  • 7

2 Answers2

0

You can pass arraylist with fragment follow below code

 List<PieEntry> entries = new ArrayList<>();
 entrie.add(additems);
 Fragment_FindABarDetail fragment;
 fragment = new Fragment_FindABarDetail().newInstance(entries);   
 fragmentManager.beginTransaction()
                        .replace(R.id.main_content, fragment).commit();

in fragment add

static List<PieEntry> entries_infragment;
public Fragment_FindABarDetail fragment newInstance(List<PieEntry> entries){

entries_infragment=entries;

return this;
}
raj
  • 2,088
  • 14
  • 23
0

Send parameters:

Fragment fragment = new Fragment();
final Bundle bundle = new Bundle();
bundle.putString("user_name", myusername);
fragment.setArguments(bundle);

Receive parameters:

Bundle args = getArguments();
if (args  != null && args.containsKey("user_name"))
String userName = args.getString("user_name");

You can also try using static methods for passing data between fragments.

Sumit Shetty
  • 112
  • 1
  • 9