get Float from EditText - Android User Interface

Android examples for User Interface:EditText

Description

get Float from EditText

Demo Code


import android.util.Log;
import android.widget.EditText;

public class Main {
  public static float getFloat(String intString) {
    try {// w  w  w  .  ja va 2s  . c  om
      return Float.parseFloat(intString);
    } catch (NumberFormatException e) {
      Log.wtf("FloatingButtons", e.toString());
      return 0;
    }
  }

  public static float getFloat(EditText view) {
    return getFloat(view.getText().toString());
  }
}

Related Tutorials