Android 动态数组
我正在通过 Android Pull Parser 技术解析 XML 文件。首先,看一下下面的 XML 文件:
<childs>
<students>
<name> hello </name>
<address> xyz </address>
</stdents>
<students>
<name> abc </name>
<address> def </address>
</stdents>
</childs>
考虑我正在解析上面的文件。现在,我的问题是我想为名称和地址创建一个单独的数组。因此,在解析时,我想将第一个学生的数据存储在 name[0]
和 address[0]
中,将下一个学生的数据存储在 name[1]
中代码> 和<代码>地址[1]。简而言之,随着解析更多数据,数组大小正在扩展。
有什么办法可以做到这一点吗?我的意思是创建一个动态可扩展数组?或者如果有其他方法可以这样做,那么请帮助我解决这个问题。
I am parsing an XML file through Android Pull Parser technique. First, have a look at the below XML file:
<childs>
<students>
<name> hello </name>
<address> xyz </address>
</stdents>
<students>
<name> abc </name>
<address> def </address>
</stdents>
</childs>
Consider that I'm parsing the above file. Now, my problem is that I want to create a separate array for name and address. So while parsing, I want to store 1st student's data in name[0]
and address[0]
and the next student's data in name[1]
and address[1]
. In short, array size is extending as more data is parsed.
Is there any way to do so? I mean to create a dynamic extendable array? Or if there is another way to do so then please help me to fight with this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
Vector
,然后(如果您需要数组)使用toArray
方法将数据复制到数组。另一种选择:
You could use
Vector<String>
and then (if you need an array) copy the data to array(s) usingtoArray
method.Another option:
您可以像这样使用 List 数组
,其中 StudyParser.getValue();是你调用来获取数据的方法
You use and List array like this
where StudyParser.getValue(); is method which u call to get data
创建无限大小数组的最简单方法是使用字符串生成器。
这允许您在运行时添加许多元素。
它有 3 个主要组成部分。
在 Android Studio 中的任何位置使用以下代码。
注意:我将其视为 HTML 字符串,“
”标签将在文本视图中创建下一行。因此,所有添加的数据将显示在新行中。
The most simple method to create an unlimited size array is using String Builder.
This allow you to add many elements in runtime.
It has 3 major components.
Use the bellow code anywhere in Android Studio.
Note: I'm treating this as HTML string and "
" tags will create the next line in text view. So, all added data will be displayed in a new line.