Reputation: 1367
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
Upvotes: 13
Views: 54835
Reputation: 6913
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
Upvotes: 34
Reputation: 5522
Without more code or a stack trace, it's hard to say, but it sounds like you haven't initialized the text view. Here's how to do it:
TextView myTextView = (TextView) findViewById(R.id.tv_text);
Where 'tv_text' is the id of the textview as defined in the xml layout file.
Hope that helped!
Upvotes: 2
Reputation: 15108
Read about DDMS and logcat to obtain a stacktrace and to see what the problem is: http://developer.android.com/guide/developing/debugging/debugging-projects.html
This is what you are looking for:
Upvotes: 1