来自服务器的 XML 用于填充 Spinner
我希望旋转器从服务器的 MySQL 填充,该网站是 PHP 的,并且可以格式化以发送 XML 或 JSON 文件。
有没有办法用这些信息填充微调器?我可以将文件保存到内存中,但如何在微调器上读取它?
是否应该将该文件另存为首选项文件,然后以这种方式读取?
任何帮助将不胜感激。
谢谢
I would like for the spinner to be populated from a server's MySQL, the website is PHP and can be formated to send an XML or JSON file.
Is there a way to populate the spinner with that information? I can save the file to memory, but how can I read it on the spinner?
Should the file be save as a Preferences file and then read that way?
Any help will be appreciated.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
各位;
经过大量的寻找、尝试、测试和做数百件事之后,我回答了我自己的问题。
这可能是 Doh 的东西!程序员的答案,但我不是程序员,我正在学习和做这个作为一个学校项目,所以我对Java的了解甚至不足以被称为“基础”。
这就是我自己的问题的答案;
现在这是解释(据我所知......)
首先我从另一个旋转器读取国家(我有“几个”旋转器连接在一起)
然后我使用这些信息来调用一个子类(我也可以发布这个)。该子类联系服务器以创建 MySQL 查询并检索所需信息;在本例中,是给定国家/地区的县(或州),列表被接收为 state1、state2、state3,[这是在服务器上的 PHP 上格式化的以提供帮助]
接下来的代码行是实际的 Spinner,有关于旋转器的信息网上有很多,所以我不会解释太多。
微调器使用此行读取保存的信息;
这允许微调器预先填充用户的选择。
然后我存储选择,我存储名称和指针。加载页面时会保存名称以完成 URL,并且会保存指针,因为 Spinner 似乎喜欢指针。
我做的最后一件事是比较,当页面加载时读取变量
oCounty
,它只是读取preference
文件并将值存储在oCounty
上code>(原始县),如果县名称发生变化,则调用refresh()
,该子类刷新页面。 [这对我来说也很痛苦]现在整个事情的工作方式是,一旦从列表中选择了一个国家/地区,页面就会转到服务器,加载该国家/地区的县/州并刷新页面,因此,在旋转器上加载值,如果国家/地区发生变化,该过程将再次加载县/州。
相同的代码用于县/州来加载城市,我只是更改了变量的名称。
我确信程序员有更好、更快、更快的方法来做到这一点,但这些是我关于如何使用存储在服务器上的 MySQL 数据库中的信息填充微调器的 2 美分。
问候;
拉蒙
Folks;
After lots of looking and trying and testing and doing hundread of other things I answered my own question.
This is something that may be a Doh! answer for programmers, but I am not a programmer, I am learning and doing this as a school project, so my knowledge of Java is not even enought to be called "basic".
This is the answer to my own question;
Now this is the explanation (as far as I undertand...)
First I read the country from another spinner (I have 'few' spinners joined together)
Then I use this information to call a subclass (I can publish this too). This subclass contacts the server to create a MySQL query an retrieves the needed information; in this case the counties (or states) for a given country, the list is received as state1,state2,state3, [this was formated on the PHP on the server to help]
The next lines of code are the actual Spinner, there is alot of information about spinner on the net, so I will not explain much of this.
The spinner read the saved information using this line;
this allows the spinner to be pre-populated with the users choice.
Then I store the selection, I store both the name and pointer. The name is saved to complete the URL when the page is loaded and the pointer is saved bacuase the Spinner seems to like pointers.
The last thing I do is a comparison, the varible
oCounty
is read when the page loads, it simply reads thepreference
file and stores the value onoCounty
(Original County), if the county name changes, then it callsrefresh()
, this subclass refreshes the page. [This too was a pain to put together for me]The way the whole thing works now is that once a country is selected from the list, the page goes to the server, loads the counties/states for the country and refreshed the page, thus loading the values on the spinner, if the country changes, the process will load the counties/states again.
The same code is used with the counties/states to load the cities, I jsut changed the variable's names.
I am sure programmers have a nicer, faster, quicker way to do this, but these are my 2 cents on how to populate spinners with iformation stored on a MySQL database on the server.
Regards;
Ramón
首先解析您的 XMl 或 JSON。然后创建将在微调器中显示的数据列表或数组。将数据传递给微调器的适配器。
例子
First parse your XMl or JSON. then create a list or array of the data which will be shown in spinner. pass the data to the adapter of the spinner.
Example
是的,Spinner 可以从解析的
XML
/JSON
的输出中填充Yes, Spinner can be populated from the output of the parsed
XML
/JSON
后端
这由Mysql数据库和Web服务器组成。
遵循的摘要步骤:
前端
Back-end
This consists of the Mysql Database and Webserver.
Summary steps to follow:
Front-end