Get text Of Activity by view id - Android User Interface

Android examples for User Interface:View Id

Description

Get text Of Activity by view id

Demo Code


//package com.java2s;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;

public class Main {
    public static String textOf(final Activity activity, int id) {
        final TextView textView = findFor(activity, id);
        return textView.getText().toString();
    }//  w  w w.  j a  v a 2 s.c  o m

    public static String textOf(final View view, int id) {
        final TextView textView = findFor(view, id);
        return textView.getText().toString();
    }

    @SuppressWarnings("unchecked")
    public static <ViewType extends View> ViewType findFor(
            Activity activity, int id) {
        return (ViewType) activity.findViewById(id);
    }

    @SuppressWarnings("unchecked")
    public static <ViewType extends View> ViewType findFor(View view, int id) {
        return (ViewType) view.findViewById(id);
    }
}

Related Tutorials