Skip to content
Advertisement

Make display data textviews invisible until a city is searched

I set my textviews on my weather app to display the data for cities when searched on my search panel (i.e temp_out.setText(response.body().getMain().getTemp() + " ℃"););. It works quite fine only that the textviews used to display those data still reflect on the app(i.e temp_out). I want to set it up in such a way that the textviews will be invisible until when a city is searched, then the data for such a city will be displayed on the textview section.

These are illustrations of what I’m trying to achieve:

This should be invisible when the app is opened(the part with a red tick): enter image description here

Then this data should be displayed after searching a city online(the part with a red tick): enter image description here

So far, I’ve tried using this code findViewById(R.id.textView9).setVisibility(View.GONE); in activity for one of my textviews(time_field).

It was totally invisible before and after searching a city and also gave this exception:

JavaScript

Then I tried using this on the layout.xml android:visibility="gone" and android:visibility="invisible" for the same textview. It was as well invisible before and after searching a city but gave no exception.

I have no other option but to ask please what is the recommended way of doing this?

Here are the textviews used in displaying the data:

This is for my Fragment:

JavaScript

and This is for my Activity:

JavaScript

I don’t know if posting the full code is required as I’m trying my possible best to follow the https://stackoverflow.com/help/minimal-reproducible-example, but if it’s needed, please let me know.

Advertisement

Answer

In XML file add android:visibility="gone" and your java class

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement