I am making an application where there is only one main Activity and it shows different Fragments with mathematical operations.
I would like the result to be shown in an AlertDialog and not in a TextView that is how I have it. I leave the code to see if anyone can lend me a hand. Thanks.
CODE:
public class AnguloFragment extends Fragment {
EditText edtText1, edtText2;
Button ebtn1;
TextView txtResultado;
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.angulo_fragment, container, false);
edtText1 = (EditText) rootView.findViewById(R.id.editText1);
edtText2 = (EditText) rootView.findViewById(R.id.editText2);
ebtn1 = (Button) rootView.findViewById(R.id.btn1);
txtResultado = (TextView) rootView.findViewById(R.id.textResultado);
ebtn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double dR = Double.parseDouble(edtText1.getText().toString());
double aN = Double.parseDouble(edtText2.getText().toString());
double aN2 = aN * 2.0 * Math.PI/360.0;
double aN3 = Math.cos(aN2);
double dC = dR * aN3;
//redondea resultado mostrando solo 2 decimales
DecimalFormat df = new DecimalFormat("0.00");
String sPi = df.format(dC);
txtResultado.setText("DISTANCIA CORREGIDA "+sPi+" metros" );
}
});
return rootView;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Angulo de situacion");
}
}