[英]How to get multiple integer values from EditText in Activity A to show min and max in TextView in Activity B?
This is regarding to an app in android studio that i'm building. 这与我正在构建的android studio中的应用有关。 I have 2 activities.
我有2个活动。
In activity A, I have 4 EditTexts that can only contain integer. 在活动A中,我有4个EditText,它们只能包含整数。 Min button:there is a button, that should calculate the minimum of those 4 numbers entered by user.
最小按钮:有一个按钮,应计算用户输入的这4个数字中的最小值。 Max button:there is a button, that should calculate the maximum of those 4 numbers entered by user.
最大值按钮:有一个按钮,应计算用户输入的这4个数字中的最大值。
In activity B, there are 6 TextView
s (4 for numbers, 2 for Min and Max). 在活动B中,有6个
TextView
(数字为4,最小和最大为2)。 When the Button
in Activity
A is pressed. 当
Activity
A中的Button
被按下时。 It should pass the numbers from the EditText
s in Activity
A to the TextView
s in Activity
B. In addition to that, it should show the average of the 4 numbers in Results TextView
. 它应当从通过数字
EditText
S IN Activity
A到TextView
S IN Activity
B.除此之外,它应该显示的4个数字的结果中的平均TextView
。
I figured out the way how to pass the numbers to the TextView
s in the second Activity
. 我想出了在第二个
Activity
如何将数字传递给TextView
的方法。 What I want is a code that calculates the min and max of the user inputs and shows the min and max result in the TextView
in Activity
B. 我想要的是一个代码,该代码计算用户输入的最小值和最大值,并在
Activity
B的TextView
中显示最小值和最大值。
First, you will need to get the numbers from all of your Textview
and set them in Integer List, After that, you can check the numbers using Collections
首先,您需要从所有
Textview
获取数字并将其设置在Integer List中,然后,您可以使用Collections
来检查数字
And the following is the example code for that: 以下是该示例代码:
List<Integer> list = Arrays.asList(100,2,3,4,5,6,7,67,2,32);
int min = Collections.min(list);
int max = Collections.max(list);
System.out.println(min);
System.out.println(max);
Output: 输出:
2
100
Of course, you will have to set the output in Textview
instead of System.out.println
当然,您将必须在
Textview
设置输出,而不是System.out.println
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.