Display a text or hide view if value is null or empty - Android User Interface

Android examples for User Interface:View Hide Show

Description

Display a text or hide view if value is null or empty

Demo Code


//package com.java2s;

import android.text.TextUtils;

import android.view.View;
import android.widget.TextView;

public class Main {
    /**/*w w w  .j  ava 2 s . c  o m*/
     * Display a text or hide view if value is null or empty
     *
     * @param textView TextView which should be filled
     * @param text     the value for the TextView
     */
    public static void showTextOrHide(final TextView textView,
            final String text) {
        if (!TextUtils.isEmpty(text)) {
            textView.setText(text);
        } else {
            textView.setVisibility(View.GONE);
        }
    }
}

Related Tutorials