简体   繁体   English

如何从活动A中的EditText获取多个整数值以在活动B中的TextView中显示最小值和最大值?

[英]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.

相关问题 如何通过从userinput(edittext)获取文本并将其放入另一个活动的textview中? - How to pass get text from userinput (edittext) and put into a textview in another activity? 如何使活动A中的edittext值出现在活动B中的列表视图中? - How to make edittext value in activity A appear in a listview in activity B? 如何将多个edittext值传递到Arraylist中,然后将其发送到另一个活动? - How to pass multiple edittext values into a Arraylist and then send it to another activity? 如何在另一个Activity中从NumberPicker获取值以显示在expendablelistview子级的textView中 - How can I get value from NumberPicker in another Activity to show on my textView in expendablelistview child 将 ListView 值传递给另一个 Activity 中的多个 EditText - Pass ListView values to multiple EditText in another Activity 如果在 Android Studio 中有一个或多个为空,如何从多个 editText 中获取数据并显示在 textView 中? - How to get data from multiple editText and show in textView if one or more is empty in Android Studio? 整数最小值和最大值 - Integer min and max values 在另一个活动中将数据从EditText传递到TextView并通过共享首选项进行使用 - Passing data from EditText to TextView in another activity and savaing it with Shared Preferences 使用setText和onClickListener将数据从EditText传输到另一个活动的TextView吗? - Transfer data from EditText to TextView of another activity using setText and onClickListener? 如何从Popup Activity中的Radio Groups中的edittext中获得价值? - How to get value in edittext from a Radio Groups in Popup Activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM