如何从XML中提取数据然后提取数据

时间:2020-12-30 15:40:11

I'm very new to Android development and Java. This is probably a simple answer but I cant seem to find the info anywhere. I know I can pull data from my XML by using:

我是Android开发和Java的新手。这可能是一个简单的答案,但我似乎无法在任何地方找到信息。我知道我可以使用以下方法从我的XML中提取数据:

Double.parseDouble(example.getText().toString());

but what I need to to is then extract the data and add it together.

但我需要的是提取数据并将其添加到一起。

Example: I pull the data and its 1234 then I need to add 1+2+3+4. Thanks for the help.

示例:我拉数据及其1234然后我需要添加1 + 2 + 3 + 4。谢谢您的帮助。

1 个解决方案

#1


0  

I'm not sure I understand the question, but if you want to add all the digits in a string then you would do this:

我不确定我理解这个问题,但是如果你想在字符串中添加所有数字,那么你会这样做:

(pseudocode)

length = number of characters in string

length =字符串中的字符数

runningtotal = 0;

runningtotal = 0;

loop through all charcaters in string, 0 to length-1

循环遍历string中的所有charcaters,0到length-1

extract character at each loop position

在每个循环位置提取字符

runningtotal += Integer.getString(character);

runningtotal + = Integer.getString(character);

But I suspect this is not actually what you're trying to do. More info?

但我怀疑这实际上并不是你想要做的。更多信息?

#1


0  

I'm not sure I understand the question, but if you want to add all the digits in a string then you would do this:

我不确定我理解这个问题,但是如果你想在字符串中添加所有数字,那么你会这样做:

(pseudocode)

length = number of characters in string

length =字符串中的字符数

runningtotal = 0;

runningtotal = 0;

loop through all charcaters in string, 0 to length-1

循环遍历string中的所有charcaters,0到length-1

extract character at each loop position

在每个循环位置提取字符

runningtotal += Integer.getString(character);

runningtotal + = Integer.getString(character);

But I suspect this is not actually what you're trying to do. More info?

但我怀疑这实际上并不是你想要做的。更多信息?