I have a tabbed activity that have two fragments the fragment1 has edit text fields and a button; the second fragment has edit text fields, i want when i press the button it takes the numbers in the edit text in fragment1 and do some calculation then show the result in fragment2 edit text. Im stuck at show the result in the second fragment here is the first fragment
public class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_activity_beam_rec, container, false);
final EditText etxb,etxh,etxd;
final EditText etxt1,etxt2,etxt3;
final Button buDesign = (Button)rootView.findViewById(R.id.buDesign);
etxb = (EditText)rootView.findViewById(R.id.editText);
etxh = (EditText)rootView.findViewById(R.id.editText2);
etxd = (EditText)rootView.findViewById(R.id.editText3);
buDesign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double b,d,h,asst;
b = Double.valueOf(etxb.getText().toString());
d = Double.valueOf(etxd.getText().toString());
h = Double.valueOf(etxh.getText().toString());
asst = fn.asst(h,b,d);
var.asttt = asst;
ActivityBeamRec.mViewPager.setPagingEnabled(true);
ActivityBeamRec.mViewPager.setCurrentItem(2);
}
});
return rootView;
}
}
and here is the second fragment
public class FragBeamRec extends Fragment {
public static FragBeamRec newInstance() {
FragBeamRec fragment = new FragBeamRec();
return fragment;
}
public FragBeamRec() {
}
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_frag_beam_rec, container, false);
TextView tass = (TextView)rootView.findViewById(R.id.txttttaasss);
tass.setText(String.valueOf(var.asttt));
return inflater.inflate(R.layout.fragment_frag_beam_rec, container, false);
}
//@Override
// public void onResume() {
// super.onResume();
// if (var.fuckjava) {
// var.fuckjava=false;
// FragmentTransaction ft = getFragmentManager().beginTransaction();
// ft.detach(this).attach(this).commit();
// }
}
}
as you can see i tried to put the result in a global variable and then use it in fragment2 but it doesn't work, i think it because it is in the on create view stage so i but a code to refresh the fragment and it doesn't work. then i tried to make it show the result in the edit text in the on resumed stage but i cant because the edit text isn't readable in the on resumed class. what can i do. please help I'm new in java