简体   繁体   中英

Android: XML from API to XML in MainActivity

This Question may be hard to present, but I'll give it a go.

So I am attempting to create an application within Android Studio that determines what phase the moon is currently in. After some research, I didn't really find anything but then I found timeanddate.com offer Astronomy API packages.

I gave the trial a go, which came with the moon phases.

Now I used a Query Builder to essentially guide me through getting the Results in XML, and received the following:

    <?xml version="1.0" encoding="UTF-8"?>
<data version="2">
  <location id="750">
    <geo>
      <name>Lord Howe Island</name>
      <state>Lord Howe Island</state>
      <country id="au">Australia</country>
      <latitude>-31.557</latitude>
      <longitude>159.086</longitude>
    </geo>
    <astronomy>
      <object name="moon">
        <day date="2018-09-03" moonphase="thirdquarter">
          <event type="thirdquarter" isotime="2018-09-03T13:07+10:30" hour="13" min="7"/>
        </day>
      </object>
    </astronomy>
  </location>
</data>

So I have the data, now I am stuck at actually getting it on an Activity in Android Studio.

To the extent of my knowledge, XML in Android Studio does not look like the XML I received, with lines such as

 android:text="text"

Can someone point me in the right direction? I have no idea where to go from here, now that I have some information to work with. Clearly, this is not a matter of copy and paste the XML from time and date. I just don't know the next steps to show something like " Lord Howe Island, Third Quarter Moon" (As seen in the XML supplied)

Thanks, everyone, even the tiniest of help is useful.

Well you have to issue the API request in the background, parse the result and update the UI.

This has anything you will need: https://developer.android.com/training/basics/network-ops/xml

Feel free to ask for more info!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM