Android TextView Get getNumber(TextView view)

Here you can find the source of getNumber(TextView view)

Description

extract an Integer out of a TextView

Parameter

Parameter Description
view - the view to read from

Return

the Integer value or NULL in case of a non-parseable String

Declaration

public static Integer getNumber(TextView view) 

Method Source Code

//package com.java2s;

import android.widget.TextView;

public class Main {
    /**/*w w w.  j  a  v a  2 s.co m*/
     * extract an Integer out of a TextView
     *
     * @param view - the view to read from
     * @return the Integer value or NULL in case of a non-parseable String
     */
    public static Integer getNumber(TextView view) {
        Integer result;
        if (!isEmpty(view)) {
            try {
                result = Integer.parseInt(getString(view));
            } catch (Exception e) {
                result = null;
            }
        } else {
            result = null;
        }
        return result;
    }

    /**
     * checks, if the passed TextView contains some text
     *
     * @param view - the TextView
     * @return true, if a non-null, non-blank string is found inside of the text view
     */
    public static boolean isEmpty(TextView view) {
        if (view != null && view.getText() != null) {
            return getString(view).length() == 0;
        }
        return false;
    }

    /**
     * extract the trimmed string value out of the passed TextView
     *
     * @param view - the view to read from
     * @return the trimmed string value from the view
     */
    public static String getString(TextView view) {
        return view.getText().toString().trim();
    }
}

Related

  1. checkTextView(TextView textView)
  2. getText(TextView textView)
  3. getText(TextView textView)
  4. getDouble(TextView view)
  5. getString(TextView view)
  6. getEditTextName( ArrayList editTextNames, ArrayList ediTextView, Context ctx)
  7. getSizeForString(String text, TextView textView)