Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting decimal number from edittext

I know something similar has already been asked, but I'm having some trouble to get a decimal number that come from keyboard.

My Java code in the onCreate method should be:

textS0 = (EditText)findViewById(R.id.editS0);
Button btn_S0 = (Button)findViewById(R.id.getS0);

btn_S0.setOnClickListener(new View.OnClickListener() 
{
    public void onClick(View v)
    {
        //how should I get here the number from keyboard?
        //I think  I should be something like
        //double S0=textS0.getText()....
    }
});

And that's what my XML file contains

<EditText
       android:id="@+id/editS0"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:ems="10"
       android:hint="@string/S0"
       android:inputType="numberDecimal" />
<Button
       android:id="@+id/getS0"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/setS0" />
</LinearLayout>
like image 646
SciPhy Avatar asked Dec 05 '25 10:12

SciPhy


1 Answers

Just do this:

double S0 = Double.parseDouble(textS0.getText().toString());
like image 139
Bilbo Beggins Avatar answered Dec 10 '25 00:12

Bilbo Beggins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!