set Text to View - Android User Interface

Android examples for User Interface:View Property

Description

set Text to View

Demo Code


//package com.java2s;

import android.app.Activity;

import android.view.View;

import android.widget.TextView;

public class Main {
    public static void setText(Activity container, int id, int resource) {
        if (container == null)
            return;

        setText(container, id, container.getString(resource));
    }//from  ww  w . j  a  v  a  2  s.co  m

    public static void setText(View container, int id, int resource) {
        if (container == null)
            return;

        setText(container, id, container.getContext().getString(resource));
    }

    public static void setText(Activity container, int id, CharSequence text) {
        if (container == null)
            return;

        setText(container.findViewById(id), text);
    }

    public static void setText(View container, int id, CharSequence text) {
        if (container == null)
            return;

        setText(container.findViewById(id), text);
    }

    public static void setText(View textView, CharSequence text) {
        ((TextView) textView).setText(text);
    }

    public static void setText(TextView textView, CharSequence text) {
        textView.setText(text);
    }
}

Related Tutorials