Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android development toggling TextView visibility

Tags:

java

android

Im having some trouble with setting textview to invisible/visible.

basicly i want this to happen when an on/off button has been clicked.

what i did is kind of like

textview.setVisibility(TextView.VISIBLE);
textview.setVisibility(TextView.INVISIBLE);

when i try executing this the emultor says that the app has stopped unexcpetedly

like image 783
Yuval Avatar asked Jul 02 '11 16:07

Yuval


People also ask

How do you make a view visible and invisible on android?

In order to set the visibility of a view you call: button. setVisibility(View. GONE);

How do you animate visibility on android?

The easiest way to animate Visibility changes is use Transition API which available in support (androidx) package. Just call TransitionManager. beginDelayedTransition method then change visibility of the view. There are several default transitions like Fade , Slide .

How do I know if TextView Ellipsized?

null){ int lines = l. getLineCount(); if ( lines > 0) if ( l. getEllipsisCount(lines-1) > 0) Log. d(TAG, "Text is ellipsized"); } } });

How can I tell if TextView is clicked android?

Inside the onClick(View v) implementation add: v. getId(); To determine whice TextView pressed.


1 Answers

Are you building this from XML or programmatically?

I would make it with an XML file then when the Activity runs change the property. Be sure to use setContentView(R.layout.main); before you try to get the TextView with findViewById(...).

Call .setVisibility(View.GONE); on the TextView to hide it.

Call .setVisibility(View.VISIBLE); to on the TextView to show it.

I have an example that does something like this. You can see the code here: https://github.com/ethankhall/Morse-Messenger/blob/master/src/com/kopysoft/MorseMessenger/Translate.java

like image 131
Ethan Avatar answered Oct 27 '22 07:10

Ethan