Edit 4: Here will be my most up to date code, I'll erase and update here as I go.
movementSetsRepsFrag.java: https://codeshare.io/GZm47
setSchemes.java: https://codeshare.io/kMdj5
ControllerData.java: https://codeshare.io/nAiSh
Results.java: https://codeshare.io/vIs5Q
Edit 3:
In setSchemes.java I removed this bit of code:
// Here I'm trying to assign a name to the Child Fragment Manager
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
// And here I'm trying to use that to call my getSpinner method
// But "getSpinnerValue()" is red in the IDE and won't compile
String parentSpinnerValue = fragmentTransaction.getSpinnerValue();
And I'm now trying something I was suggested on another forum, a callback technique someone was showing me (as a way to getParentFragment):
in setSchemes.java
// above onCreateView
public interface setSchemesCallback{
String getSpinnerValue();
}
private setSchemesCallback callback;
// in onCreateView
callback = (setSchemesCallback) getParentFragment();
// in onPause
String parentSpinnerValue = callback.getSpinnerValue();
Edit 2:
Here is the object that I use to collect and organize my data, ControllerData.java
public class ControllerData {
public String exSpinnerValue1;
// DECLARE ARRAYS
String[] exArray1 = new String[15];
String[] exArray2 = new String[15];
private static ControllerData controller;
public static ControllerData getInstance(){
if (controller == null){
controller = new ControllerData();
}
return controller;
}
// PARENT SPINNER SETTERS
public void setExSpinnerValue1(String text){
if(exArray1[0] == null){
exArray1[0] = text;
}else if(exArray2[0] == null){
exArray2[0] = text;
}
}
int a1 = 1;
int b1 = 1;
// CHILD STRING VALUE SETTERS
public void setEditTextValue1(String setSchemeValue, String parentSpinnerValue){
if(exArray1[0].equals(parentSpinnerValue)){
if(exArray1[a1] == null){
exArray1[a1] = setSchemeValue;
a1++;
}
}
if(exArray2[0].equals(parentSpinnerValue)){
if(exArray2[b1] == null){
exArray2[b1] = setSchemeValue;
b1++;
}
}
}
}
Edit: Alright, so now I'm trying to use getChildFragmentManager in setSchemes(the nested frag), because it seems I can call getParentFragment if the parent is a child of an activity. This is what I have now, I'm pretty sure my syntax is all messed up though:
setSchemes.java
@Override
public void onPause(){
super.onPause();
// Here I'm trying to assign a name to the Child Fragment Manager
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
// And here I'm trying to use that to call my getSpinner method
// But "getSpinnerValue()" is red in the IDE and won't compile
String parentSpinnerValue = fragmentTransaction.getSpinnerValue();
EditText setsEditText = (EditText) getView().findViewById(R.id.sets);
EditText repsEditText = (EditText) getView().findViewById(R.id.reps);
EditText weightEditText = (EditText) getView().findViewById(R.id.weight);
String value = setsEditText.getText().toString() + " x " + repsEditText.getText().toString() + " @ " +
weightEditText.getText().toString();
ControllerData.getInstance().setEditTextValue1(value, parentSpinnerValue);
}
So, I'm "in" a nested fragment. This nested fragment is created on a button click from a parent fragment. Many instances can be created, as many as the user wants based on how many times they click the button. The parents themselves are added dynamically as well. The differences between them are the spinner values selected. I then pass those nested fragments' values into an object. I need the nested fragments to "know" which parent fragment they "belong" to, and the way I'm trying to do that is call for the parent's spinner value and then pass that value with the nested fragment's own value. This way I can determine programmatically which array to pass the nested values to.
This is the parent fragment, movementSetsReps.java
// Here in onPause I send my spinner value to my ControllerData.
// I send the spinner value to an array at index [0]
// This is so that later I can compare the value in array[0]
//with the value passed with the nested fragment
@Override
public void onPause() {
super.onPause();
Spinner exerciseSpinner = (Spinner) getView().findViewById(R.id.movementName);
String spinnerText = exerciseSpinner.getSelectedItem().toString();
ControllerData.getInstance().setExSpinnerValue1(spinnerText);
}
// Here is where I set up the method that should be called by the nested fragment
public String getSpinnerValue(){
Spinner exerciseSpinner = (Spinner) getView().findViewById(R.id.movementName);
String spinnerText = exerciseSpinner.getSelectedItem().toString();
return spinnerText;
}
Now for the nested fragment, setSchemes.java
@Override
public void onPause(){
super.onPause();
// I thought this would work but it's not. This should call
// the method in whatever is the parent fragment
String parentSpinnerValue = ((movementSetsRepsFrag) getParentFragment()).getSpinnerValue();
// Everything below here pertains to the sending of a string to ControllerData's arrays.
EditText setsEditText = (EditText) getView().findViewById(R.id.sets);
EditText repsEditText = (EditText) getView().findViewById(R.id.reps);
EditText weightEditText = (EditText) getView().findViewById(R.id.weight);
String value = setsEditText.getText().toString() + " x " + repsEditText.getText().toString() + " @ " +
weightEditText.getText().toString();
ControllerData.getInstance().setEditTextValue1(value, parentSpinnerValue);
}
Now in my results.java I have some log methods that tell me what my arrays end up containing. I get null every time.
Log.d("array1", ControllerData.getInstance().exArray1[0] + " " + ControllerData.getInstance().exArray1[1]);
Log.d("array2", ControllerData.getInstance().exArray2[0] + " " + ControllerData.getInstance().exArray2[1]);
My output looks like: "array1 null null" instead of, for example, "bench press 2x15@135 3x10@115"