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
Solution 1:
Just do this:
double S0 = Double.parseDouble(textS0.getText().toString());
Solution 2:
textS0=(EditText)findViewById(R.id.editS0);
Button btn_S0=(Button)findViewById(R.id.getS0);
btn_S0.setOnClickListener(new View.OnClickListener()
{
publicvoidonClick(View v)
{
double S0 = Double.parseDouble(textS0.getText().toString());
}
});
Solution 3:
May b you face null pointer exception in string so try this....
get the number decimal from edittext using this
Double BText=ParseDouble(String.valueOf(edittext.getText()));
after that paste this code.. it prevents you from null pointer exception
double ParseDouble(String strNumber) { if (strNumber != null && strNumber.length() > 0) { try { returnDouble.parseDouble(strNumber); } catch(Exception e) { return -1; } } elsereturn0; }
Post a Comment for "Getting Decimal Number From Edittext"