set Text For Activity - Android Activity

Android examples for Activity:Activity Action

Description

set Text For Activity

Demo Code


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

public class Main {
    public static void setTextFor(final Activity activity, final int id,
            final String text) {
        final TextView textView = findFor(activity, id);
        textView.setText(text);/*from  w  w  w.  j a  v  a 2  s .  c o  m*/
    }

    public static void setTextFor(final View view, final int id,
            final String text) {
        final TextView textView = findFor(view, id);
        textView.setText(text);
    }

    @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