get Integer From EditText - Android User Interface

Android examples for User Interface:EditText

Description

get Integer From EditText

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;
import android.widget.EditText;

public class Main {
    private static final Integer ZERO = 0;

    @SuppressLint("NewApi")
    public static Integer getIntegerFrom(EditText editText) {
        String stringValueFromEditText = getStringFrom(editText);
        return stringValueFromEditText.isEmpty() ? ZERO : Integer
                .valueOf(stringValueFromEditText);
    }/*  w w w  .j  av a2s  .  c  o  m*/

    public static String getStringFrom(EditText editText) {
        return editText.getText().toString();
    }
}

Related Tutorials