Example usage for android.widget TextView setVisibility

List of usage examples for android.widget TextView setVisibility

Introduction

In this page you can find the example usage for android.widget TextView setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:Main.java

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);//from   w w  w. j a  v  a  2  s . c  o m
        } else {
            textView.setVisibility(View.GONE);
        }
    }
}

From source file:Main.java

private static void setText(TextView view, String text, boolean keepHtml) {
    CharSequence displayText = null;
    if (text != null) {
        displayText = keepHtml ? Html.fromHtml(text) : Html.fromHtml(text).toString();
    }//w  w w. j a v  a 2  s .  c o  m
    if (view != null) {
        if (displayText != null && !"".equals(displayText)) {
            view.setVisibility(View.VISIBLE);
            view.setText(displayText);
        } else {
            view.setVisibility(View.GONE);
        }
    }
}

From source file:com.krayzk9s.imgurholo.tools.ImageUtils.java

public static void updateImageFont(JSONParcelable imageData, TextView imageScore) {
    try {/*from w w  w  .ja  v a 2s. c  o  m*/
        if (!imageData.getJSONObject().has("vote")) {
            imageScore.setVisibility(View.GONE);
            return;
        }
        if (imageData.getJSONObject().getString("vote") != null
                && imageData.getJSONObject().getString("vote").equals("up"))
            imageScore.setText(Html.fromHtml("<font color=#89c624>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score"))
                    + " points </font> (<font color=#89c624>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups"))
                    + "</font>/<font color=#ee4444>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("downs"))
                    + "</font>)"));
        else if (imageData.getJSONObject().getString("vote") != null
                && imageData.getJSONObject().getString("vote").equals("down"))
            imageScore.setText(Html.fromHtml("<font color=#ee4444>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score"))
                    + " points </font> (<font color=#89c624>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups"))
                    + "</font>/<font color=#ee4444>"
                    + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("downs"))
                    + "</font>)"));
        else
            imageScore.setText(Html.fromHtml(
                    NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("score"))
                            + " points (<font color=#89c624>"
                            + NumberFormat.getIntegerInstance().format(imageData.getJSONObject().getInt("ups"))
                            + "</font>/<font color=#ee4444>" + NumberFormat.getIntegerInstance()
                                    .format(imageData.getJSONObject().getInt("downs"))
                            + "</font>)"));
    } catch (JSONException e) {
        Log.e("Error font!", e.toString());
    }
}

From source file:com.battlelancer.seriesguide.util.Utils.java

/**
 * If the given double is larger than 0, will make the label and value field {@link
 * View#VISIBLE}. Otherwise both {@link View#GONE}.
 *
 * @return True if the views are visible.
 *//*from   w  w w  .  ja  v a2  s .c  o m*/
public static boolean setLabelValueOrHide(View label, TextView text, double value) {
    if (value > 0.0) {
        label.setVisibility(View.VISIBLE);
        text.setVisibility(View.VISIBLE);
        text.setText(String.valueOf(value));
        return true;
    } else {
        label.setVisibility(View.GONE);
        text.setVisibility(View.GONE);
        return false;
    }
}

From source file:com.battlelancer.seriesguide.util.Utils.java

/**
 * If the given string is not null or empty, will make the label and value field {@link
 * View#VISIBLE}. Otherwise both {@link View#GONE}.
 *
 * @return True if the views are visible.
 *//*from  w  ww .j  a va 2  s.  c o  m*/
public static boolean setLabelValueOrHide(View label, TextView text, final String value) {
    if (TextUtils.isEmpty(value)) {
        label.setVisibility(View.GONE);
        text.setVisibility(View.GONE);
        return false;
    } else {
        label.setVisibility(View.VISIBLE);
        text.setVisibility(View.VISIBLE);
        text.setText(value);
        return true;
    }
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

/**
 * Select a custom item from a list, and call halder when/if item is selected.
 *//* ww w . j  a  v a  2  s . co m*/
public static void selectItemDialog(LayoutInflater inflater, String message, ArrayList<SimpleDialogItem> items,
        SimpleDialogItem selectedItem, final SimpleDialogOnClickListener handler) {
    // Get the view and the radio group
    final View root = inflater.inflate(R.layout.select_list_dialog, null);
    TextView msg = (TextView) root.findViewById(R.id.message);

    // Build the base dialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(inflater.getContext()).setView(root);
    if (message != null && !message.equals("")) {
        msg.setText(message);
    } else {
        msg.setVisibility(View.GONE);
    }

    final AlertDialog dialog = builder.create();

    // Create the listener for each item
    OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            SimpleDialogItem item = (SimpleDialogItem) ViewTagger.getTag(v, R.id.TAG_DIALOG_ITEM);
            // For a consistent UI, make sure the selector is checked as well. NOT mandatory from
            // a functional point of view, just consistent
            if (!(v instanceof RadioButton)) {
                RadioButton btn = item.getSelector(v);
                if (btn != null) {
                    btn.setChecked(true);
                    btn.invalidate();
                }
            }
            //
            // It would be nice to have the other radio buttons reflect the new state before it
            // disappears, but not really worth the effort. Esp. since the code below does not work...
            // and the dialog disappears too fast to make this worthwhile.
            //
            //LinearLayout list = (LinearLayout)root.findViewById(R.id.list);
            //for(int i = 0; i < list.getChildCount(); i++) {
            //   View child = list.getChildAt(i);
            //   SimpleDialogItem other = (SimpleDialogItem)ViewTagger.getTag(child, R.id.TAG_DIALOG_ITEM);
            //   RadioButton btn = other.getSelector(child);
            //   btn.setSelected(other == item);
            //   btn.invalidate();
            //}
            dialog.dismiss();
            handler.onClick(item);
        }
    };

    // Add the items to the dialog
    LinearLayout list = (LinearLayout) root.findViewById(R.id.list);
    for (SimpleDialogItem item : items) {
        View v = item.getView(inflater);
        v.setBackgroundResource(android.R.drawable.list_selector_background);
        ViewTagger.setTag(v, R.id.TAG_DIALOG_ITEM, item);
        list.addView(v);
        v.setOnClickListener(listener);
        RadioButton btn = item.getSelector(v);
        if (btn != null) {
            ViewTagger.setTag(btn, R.id.TAG_DIALOG_ITEM, item);
            btn.setChecked(item == selectedItem);
            btn.setOnClickListener(listener);
        }
    }
    dialog.show();
}

From source file:com.androidinspain.deskclock.Utils.java

/**
 * Clock views can call this to refresh their alarm to the next upcoming value.
 *//*from   w w  w.  j a  v a 2 s .  co  m*/
public static void refreshAlarm(Context context, View clock) {
    final TextView nextAlarmIconView = (TextView) clock.findViewById(R.id.nextAlarmIcon);
    final TextView nextAlarmView = (TextView) clock.findViewById(R.id.nextAlarm);
    if (nextAlarmView == null) {
        return;
    }

    final String alarm = getNextAlarm(context);
    if (!TextUtils.isEmpty(alarm)) {
        final String description = context.getString(R.string.next_alarm_description, alarm);
        nextAlarmView.setText(alarm);
        nextAlarmView.setContentDescription(description);
        nextAlarmView.setVisibility(View.VISIBLE);
        nextAlarmIconView.setVisibility(View.VISIBLE);
        nextAlarmIconView.setContentDescription(description);
    } else {
        nextAlarmView.setVisibility(View.GONE);
        nextAlarmIconView.setVisibility(View.GONE);
    }
}

From source file:com.android.deskclock.Utils.java

/** Clock views can call this to refresh their alarm to the next upcoming value. */
public static void refreshAlarm(Context context, View clock) {
    final TextView nextAlarmView = (TextView) clock.findViewById(R.id.nextAlarm);
    if (nextAlarmView == null) {
        return;/*from   ww  w .j ava 2s .  c o  m*/
    }

    final String alarm = getNextAlarm(context);
    if (!TextUtils.isEmpty(alarm)) {
        final String description = context.getString(R.string.next_alarm_description, alarm);
        nextAlarmView.setText(alarm);
        nextAlarmView.setContentDescription(description);
        nextAlarmView.setVisibility(View.VISIBLE);
    } else {
        nextAlarmView.setVisibility(View.GONE);
    }
}

From source file:com.chatwing.whitelabel.adapters.ChatboxesAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    int dataIndexColumn = cursor.getColumnIndex(ConversationTable.DATA);
    ChatBox conversation = new Gson().fromJson(cursor.getString(dataIndexColumn), ChatBox.class);

    ((TextView) view.findViewById(android.R.id.text1)).setText(conversation.getName());
    ((TextView) view.findViewById(android.R.id.text2)).setText("/" + conversation.getAlias());

    int countIndexColumn = cursor.getColumnIndex(ChatBoxTable.UNREAD_COUNT);
    int count = cursor.getInt(countIndexColumn);
    TextView countTv = (TextView) view.findViewById(R.id.unread_count);
    if (count == 0) {
        countTv.setVisibility(View.GONE);
    } else {/*from   w  w  w .  ja va  2  s . c o m*/
        countTv.setText(String.valueOf(count));
        countTv.setVisibility(View.VISIBLE);
    }
}

From source file:com.chatwingsdk.adapters.ConversationsAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    int dataIndexColumn = cursor.getColumnIndex(ConversationTable.DATA);
    Conversation conversation = new Gson().fromJson(cursor.getString(dataIndexColumn), Conversation.class);

    ((TextView) view.findViewById(android.R.id.text1))
            .setText(conversation.getConversationAlias(mCurrentUser.getId()));

    int countIndexColumn = cursor.getColumnIndex(ConversationTable.UNREAD_COUNT);
    int count = cursor.getInt(countIndexColumn);
    TextView countTv = (TextView) view.findViewById(R.id.unread_count);
    if (count == 0) {
        countTv.setVisibility(View.GONE);
    } else {//from  w ww . jav  a  2 s  . co m
        countTv.setText(String.valueOf(count));
        countTv.setVisibility(View.VISIBLE);
    }
}