« first day  last day (15 days later) » 

6:36 AM
Firstly, go to FirstFragment.java and remove line 87 which is getWeatherData, this is not required since this is called as soon as the app starts and the search text field is empty which returns an error.
Instead, what we need to do is call the getWeather function that is inside the FirstFragment.java from HomeActivity.java when Search is pressed.
For that add the following code after line 60 at line 61 in HomeActivity.java

FirstFragment firstFragment = (FirstFragment) navHostFragment.getChildFragmentManager().getFragments().get(0);
firstFragment.getWeatherData(textfield.getText().toString().trim());
what that does is get the first fragment and casts it to FirstFragment.java and then calls the getWeatherData of the fragment itself since that populates all the fields with the data obtained from the API
This is the easiest way to get your code working based on how its currently setup
 
 
1 hour later…
7:58 AM
After implementing the setup, it runs with no error but is only able to display the dt data(which is on the homeActivity, it's unable to display any data from the fragment
 
did you correctly add

FirstFragment firstFragment = (FirstFragment) navHostFragment.getChildFragmentManager().getFragments().get(0);
firstFragment.getWeatherData(textfield.getText().toString().trim());

to line 61? This is what would update data in the fragment? I tried it on my end and it works fine
line 61 in HomeActivity.java would mean inside the click listener of the Search button
 
That was the exact thing I did unless maybe you added /removed another code that you did not mention
 
Right, change getWeatherData method in the Firstfragment to be public
 
8:14 AM
I did that, it still doesn't run
 
So HomeActivity should have this
And FirstFragment should have this
 
Are you sure you did not add q=London in the interface address? Can you search any city there?
 
yup i can search any city
 
Wow I still get the same result, I don't just know what is wrong
 
so after u type u tap the search icon right?
 
8:25 AM
Yes
 
can u post a screenshot of homeactivity?
and first fragment
 
How can i upload screenshot on chat please?
 
next to the box where u type, there is an upload button. Tap on that and browse the screenshot from your computer
 
i can't see any upload button here
 
hmm maybe you dont have the privileges yet then. Can you upload to imgur.com? and paste the link here then
 
everything looks correct there, finally can i see a screenshot for ApiInterface too?
 
That link isnt correct
 
That looks correct too, hmm can I also see ApiClient.java then?
 
8:45 AM
It runs now, I removed int id = Objects.requireNonNull(navController.getCurrentDestination()).getId();
navController.popBackStack();
navController.navigate(id);
 
oh i dont even have that code with me from what you shared earlier
 
from the home activity. I can't hide my excitement, you helped me with a bug I had for almost 2 months. Thanks a lot, bro! I'll accept now
 
All good, thank you too.
 
Yeah, please what do you think about dt that doesn't display the hh:mm format. I want to use what you suggested without using the pretty time seriezer
 
8:59 AM
Keep everything as is and you can add this method to Example.java

public String getPrettyDate() {
SimpleDateFormat HMM = new SimpleDateFormat("hh:mm a", Locale.US);
final Date date = new Date(dt);
return HMM.format(date);
}

and then where u call getDt() in HomeActivity call getPrettyDate()
with this logic you dont need a custom deserializer for Gson but you are just converting the value in dt in your model to a more readable format and then displaying it
oh sorry that should be

public String getPrettyDate() {
SimpleDateFormat HMM = new SimpleDateFormat("hh:mm a", Locale.US);
final Date date = new Date(dt * 1000);
return HMM.format(date);
}
converting dt seconds to milliseconds
 
Ohh thanks for your suggestion
 

« first day  last day (15 days later) »