0

I am stuck on this problem for two weeks now and i am not going to solve it on my own it seems, so i hope you can help me out.

All i need is a working arraylist that can be accessed normally where it says entries in my code.

To be a little bit more specific:

In the "SecondFragment":

Go to the OnClickListener

There it says entries.add(new PieEntry(number, nomen));

This is the part where a new entry is made in the arraylist that i fail to create.

Then in the "FirstFragment"

It says at the button2.OnClickListener

PieDataSet set = new PieDataSet(entries, "");

This is where i need to receive the data from "SecondFragment"

AND THAT'S IT

Nothing more, no other things necessaray to help me out.

Thanks in advance, and my best regards,

Niklas

SECONDFRAGMENT

public class SecondFragment extends Fragment {
// Store instance variables
private String title;
private int page;

// newInstance constructor for creating fragment with arguments
public static SecondFragment newInstance(int page, String title) {
    SecondFragment fragmentSecond = new SecondFragment();
    Bundle args = new Bundle();
    args.putInt("someInt", page);
    args.putString("someTitle", title);
    fragmentSecond.setArguments(args);
    return fragmentSecond;
}

// Store instance variables based on arguments passed
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    page = getArguments().getInt("someInt", 0);
    title = getArguments().getString("someTitle");
}

// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_second, container, false);
    TextView tvLabel2 = (TextView) view.findViewById(R.id.textView2);

    //Alle Objekte hier einfügen (wie textview tvavel2)

    final Button button = (Button) view.findViewById(R.id.button);
    final TextView textView = (TextView) view.findViewById(R.id.textView);
    final TextView textView2 = (TextView) view.findViewById(R.id.textView2);
    final EditText editText = (EditText) view.findViewById(R.id.editText);
    final EditText editText2 = (EditText) view.findViewById(R.id.editText2);
    final EditText editText3 = (EditText) view.findViewById(R.id.editText3);



    button.setOnClickListener(new View.OnClickListener() {
        public void onClick (View view) {



            if (editText3.getText().toString().matches("")) {
                Toast.makeText(getActivity(), "You did not enter a Valid Item ID", Toast.LENGTH_LONG).show();
                return;
            }

            else if (editText2.getText().toString().matches("")) {
                Toast.makeText(getActivity(), "You did not enter a Valid Quantitiy", Toast.LENGTH_LONG).show();
                return;

            }

            else {

                String nomen = (editText3.getText().toString());
                float number = Float.parseFloat(editText2.getText().toString());

                entries.add(new PieEntry(number, nomen));

                editText3.setText("");
                editText2.setText("");
                editText3.requestFocus();
            }
        }
    });

    return view;
}

And:

FIRSTFRAGMENT

public class FirstFragment extends Fragment {
// Store instance variables
private String title;
private int page;


// newInstance constructor for creating fragment with arguments
public static FirstFragment newInstance(int page, String title) {
    FirstFragment fragmentFirst = new FirstFragment();
    Bundle args = new Bundle();
    args.putInt("someInt", page);
    args.putString("someTitle", title);
    fragmentFirst.setArguments(args);
    return fragmentFirst;
}

// Store instance variables based on arguments passed
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    page = getArguments().getInt("someInt", 0);
    title = getArguments().getString("someTitle");
}

// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_first, container, false);
    EditText editText = (EditText) view.findViewById(R.id.editText);
    final PieChart piechart = (PieChart) view.findViewById(R.id.piechart);
    final Button button2 = (Button) view.findViewById(R.id.button2);

    new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int position) {


        }
    };











    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick (View view) {
            getResources().getColor(R.color.violp);
            getResources().getColor(R.color.bluep);
            getResources().getColor(R.color.redp);
            getResources().getColor(R.color.greenp);
            getResources().getColor(R.color.yellowp);
            getResources().getColor(R.color.orangep);
            getResources().getColor(R.color.lightbluep);
            getResources().getColor(R.color.purplep);
            getResources().getColor(R.color.darkredp);

            PieDataSet set = new PieDataSet(entries, "");


            set.setColors(new int[]{R.color.bluep, R.color.greenp, R.color.violp, R.color.redp, R.color.yellowp, R.color.orangep, R.color.lightbluep, R.color.purplep, R.color.darkredp}, getActivity());
            PieData datax = new PieData(set);
            piechart.setData(datax);

            Toast.makeText(getActivity(), (R.string.loading),
                    Toast.LENGTH_SHORT).show();

            piechart.setNoDataText(String.valueOf(R.string.nodata));
            piechart.notifyDataSetChanged();
            piechart.animateX(2000, Easing.EasingOption.EaseInExpo);
            piechart.animateY(2000, Easing.EasingOption.EaseInExpo);



            }



        });






    return view;
}

PS: If i could ask this question better or should not ask at all, let me know. I am willing to become a better community member, thanks.

Niklas Daute
  • 75
  • 1
  • 7

0 Answers0