Reputation: 279
I have a textview in an activity. I am changing its visibility.
if(CheckBookmark(Constants.versusHeading.get(curVCount))) {
bookmark.setVisibility(View.VISIBLE);
bookmark.setText("Bookmarked");
}
else {
bookmark.setVisibility(View.GONE);
}
but UI is not updated. I have tried bookmark.invalidate()
and bookmark.postinvalidate()
but didn't work. If I change textview visibility how do I refresh UI? Activity is still alive and running.
Okay I think I need to add more details. My bad should have mentioned in the first place....Initially when activity is displayed bookmark is visible but have no text.
Then user creates a bookmark. Checkbookmark returns true if bookmark is successfully created. In that case I add bookmarked as text. I am setting it to visible as it wasn't working. If I quit activity and come back then bookmark text is displayed.
Upvotes: 1
Views: 449
Reputation: 23962
As Pramod says, try
setVisibility(View.INVISIBLE)
instead of
setVisibility(View.GONE)
Upvotes: 0
Reputation: 26981
In general it should work the way you have it. The UI will update.
You need to make sure your if else is returning correctly.
Try setting the textview to VISIBILE intially to see if it appears and then try to toggle the TextView's visibility
Upvotes: 1