Reads a user-entered value as a Double from EditText - Android User Interface

Android examples for User Interface:EditText

Description

Reads a user-entered value as a Double from EditText

Demo Code


//package com.java2s;

import android.view.View;

import android.widget.EditText;

public class Main {
    /**//from   ww  w .j  av  a2s .  c om
     * Reads a user-entered value as a Double.
     * @param rootView view containing the specified input field
     * @param inputId e.g R.id.conductivity_input
     * @return the value entered, or null if the value is empty
     */
    public static Double getNumericInput(View rootView, int inputId) {
        String value = ((EditText) rootView.findViewById(inputId))
                .getText().toString();
        if (!value.isEmpty()) {
            return Double.parseDouble(value);
        } else {
            return null;
        }
    }
}

Related Tutorials