Java tutorial
//package com.java2s; import android.text.TextUtils; import android.view.View; import android.widget.TextView; public class Main { public static void setText(TextView textView, String text) { if (textView != null && !TextUtils.isEmpty(text)) { textView.setVisibility(View.VISIBLE); textView.setText(text); } } public static void setText(TextView textView, boolean visible, String text) { if (textView != null) { if (visible && !TextUtils.isEmpty(text)) { textView.setVisibility(View.VISIBLE); textView.setText(text); } else { textView.setVisibility(View.GONE); } } } public static void setVisibility(View view, boolean visible) { if (view != null) { view.setVisibility(visible ? View.VISIBLE : View.GONE); } } }