Extract text from an TextView. - Android User Interface

Android examples for User Interface:TextView

Description

Extract text from an TextView.

Demo Code


//package com.java2s;
import android.app.Activity;

import android.widget.EditText;

public class Main {
    /**//from   w  w  w .j  a  va  2 s  .  com
     * Extract text from an TextView.
     * PRECONDITION: Assumes id represents a valid EditText view
     * @param id the id of an EditText view to get string from
     * @return string contained in EditText view with id
     */
    public static String getViewText(Activity a, int id) {
        EditText editTextView = (EditText) a.findViewById(id);
        String fieldText = editTextView.getText().toString();
        return fieldText;
    }
}

Related Tutorials