Reputation: 299
Let me try to explain my question in detail. I have 5 tabs and my Tab class is run after the Splash screen of my application, and the first tab will be displayed.
In my first tab, I have a class that contains a TextView that will display certain text under some condition (related to profile keyed in by the user in another class).
TextView duration = (TextView)view.findViewById(R.id.duration);
duration.setText(durationNumber);
if(week <= 12)
{
durationNumber = "Less than 12 weeks";
}
else
{
durationNumber = "More than 12 weeks";
}
When I run my application, the text does not appear, unless i navigate to other tabs and return to the first tab. I googled around and couldn't find a solution. I've tried using SharedPreferences but it didn't work. Perhaps I did it wrongly.
Why is this happening and how can I fix this?
Upvotes: 0
Views: 105
Reputation: 5244
What is the initial value of durationNumber
? Is it null
before it is set in the if-else loop? If it is null
then the TextView will not appear (as there is no value to display).
You will have to set the TextView
text again after the if-else loop. Try this...
TextView duration = (TextView)view.findViewById(R.id.duration);
if(week <= 12) {
durationNumber = "Less than 12 weeks";
} else {
durationNumber = "More than 12 weeks";
}
duration.setText(durationNumber);
Upvotes: 2