

Text: In this parameter, you should enter the data to be displayed in the toast. If you are in the inner class, you can use the function getApplicationContext(). Here we have to mention three parameters.Ĭontext: You have to mention the context in which you are making the toast. For our weight converter app, we will display the output in a toast. What is toast? It’s the message the system displays when your phone connects to a WiFi network. Toast is the easiest way to display information in an Android app. The code looks like this:ĭouble newVariable = doubleVariable * 2.20462 ĭoubleVariable = doubleVariable * 2.20462 Displaying the output in a toast: Alternatively, we can also update our original doubleVariable because we don’t need to use it ahead in our app. So we just multiply our variable with 2.20462 and store the new value in another variable. 1 kg is approximately equal to 2.20462 lbs. Quite similar to how we use arithmetic operators in C, we can perform arithmetic operations on our variable using our standard syntax ( +, -, *, /, %). We don’t need to define the string variable because we can get similar results from the following code too:ĭouble doubleVariable = Double.parseDouble( editTextVariable.getText().toString()) īoth the methods are correct so any one can be used. It’s also in the data type that we need, i.e., Double. We have the value from the input field stored in our Double variable. The syntax for this looks like this:ĭouble doubleVariable = Double.parseDouble( stringVariable) Just like with the conversion to a string, we first define a variable of a double datatype. Convert String data type into Double data type: But since we are dealing with numbers, we have to use the Double data type to hold this value. Now, stringVariable holds the data in String form. String stringVariable = editTextVariable.getText().toString() We do this by using two functions, getText() and toString(). This variable will hold the value from editTextVariable in the form of a string.

Convert this data into a String data type: Now the variable editTextVariable will have the value entered by the user in the text field with the id textFieldName. EditText editTextVariable = (EditText) findViewById (R.id.
