Return the text the TextView is displaying. - Android User Interface

Android examples for User Interface:TextView

Description

Return the text the TextView is displaying.

Demo Code

/*//w w w . jav a2  s . c o m
 * Copyright (c) 2014 Remel Pugh
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
//package com.java2s;
import android.text.TextUtils;

import android.widget.EditText;

public class Main {
    /**
     * Return the text the TextView is displaying.
     *
     * @param view The {@link EditText} used to retrieve the text.
     *
     * @return The text of the {@link EditText} view, otherwise null.
     */
    @SuppressWarnings("ConstantConditions")
    public static String getText(final EditText view) {
        if (view != null && !TextUtils.isEmpty(view.getText())) {
            return view.getText().toString();
        }

        return null;
    }

    /**
     * Determines if all {@link EditText} views supplied are empty.
     *
     * @param views {@link EditText} views to be checked.
     *
     * @return true if all {@link EditText} views are empty, false otherwise.
     */
    @SuppressWarnings("ConstantConditions")
    public static boolean isEmpty(final EditText... views) {
        for (final EditText view : views) {
            if (view != null) {
                if (!TextUtils.isEmpty(view.getText().toString())) {
                    return false;
                }
            }
        }

        return true;
    }
}

Related Tutorials