get EditText As Value Trim To Null - Android User Interface

Android examples for User Interface:EditText

Description

get EditText As Value Trim To Null

Demo Code


//package com.book2s;
import android.widget.EditText;

public class Main {
    public static String getEditTextAsValueTrimToNull(EditText view) {
        String nameDirty = view.getText().toString();
        return trimToNull(nameDirty);
    }//from  w  w w.j av  a  2  s.c o m

    public static String trimToNull(String nameDirty) {
        String name = nameDirty;
        if (name != null) {
            name = name.trim();
            if (name.length() < 1) {
                name = null;
            }
        }
        return name;
    }
}

Related Tutorials