I assume you want to convert a String to a float or double?
String input = "3.14";
float x = Float.parseFloat(input);
This code converts the String "3.14" into a float. You can use this float in the function you described in the question.
EDIT: If you want to convert the full function String into Java code, you should limit the input to buttons. For example, add a button named "Cos", and remember in the code the user wants to use the Cosinus function. Then the user enters a value, and presses "Enter". The code knows it should use the cosinus function, and x is the value entered in an EditText. That value should be parsed using Float.parseFloat().