How to calculate min value of 4 EditTexts in Android?
This is an app.
I have 4 EditTexts. which the user enter the number.
There is a min button.
When the user clicks on the min button, it should calculate the minimum of the 4 numbers that were entered by the users.
java android
add a comment |
This is an app.
I have 4 EditTexts. which the user enter the number.
There is a min button.
When the user clicks on the min button, it should calculate the minimum of the 4 numbers that were entered by the users.
java android
what have you tried ? Have you successfully get the text from editText ?
– John Joe
Nov 13 '18 at 3:29
I figured out that part. i'm stuck in getting the result and showing it in the textview.
– FrancoMedicci
Nov 13 '18 at 3:46
post the code so we can help
– John Joe
Nov 13 '18 at 3:46
1
This sounds like homework.
– majidarif
Nov 13 '18 at 6:05
I figured it out and yes this is an assignment.
– FrancoMedicci
Nov 14 '18 at 0:32
add a comment |
This is an app.
I have 4 EditTexts. which the user enter the number.
There is a min button.
When the user clicks on the min button, it should calculate the minimum of the 4 numbers that were entered by the users.
java android
This is an app.
I have 4 EditTexts. which the user enter the number.
There is a min button.
When the user clicks on the min button, it should calculate the minimum of the 4 numbers that were entered by the users.
java android
java android
edited Nov 13 '18 at 6:05
Shashanth
2,49642136
2,49642136
asked Nov 13 '18 at 3:28
FrancoMedicci
63
63
what have you tried ? Have you successfully get the text from editText ?
– John Joe
Nov 13 '18 at 3:29
I figured out that part. i'm stuck in getting the result and showing it in the textview.
– FrancoMedicci
Nov 13 '18 at 3:46
post the code so we can help
– John Joe
Nov 13 '18 at 3:46
1
This sounds like homework.
– majidarif
Nov 13 '18 at 6:05
I figured it out and yes this is an assignment.
– FrancoMedicci
Nov 14 '18 at 0:32
add a comment |
what have you tried ? Have you successfully get the text from editText ?
– John Joe
Nov 13 '18 at 3:29
I figured out that part. i'm stuck in getting the result and showing it in the textview.
– FrancoMedicci
Nov 13 '18 at 3:46
post the code so we can help
– John Joe
Nov 13 '18 at 3:46
1
This sounds like homework.
– majidarif
Nov 13 '18 at 6:05
I figured it out and yes this is an assignment.
– FrancoMedicci
Nov 14 '18 at 0:32
what have you tried ? Have you successfully get the text from editText ?
– John Joe
Nov 13 '18 at 3:29
what have you tried ? Have you successfully get the text from editText ?
– John Joe
Nov 13 '18 at 3:29
I figured out that part. i'm stuck in getting the result and showing it in the textview.
– FrancoMedicci
Nov 13 '18 at 3:46
I figured out that part. i'm stuck in getting the result and showing it in the textview.
– FrancoMedicci
Nov 13 '18 at 3:46
post the code so we can help
– John Joe
Nov 13 '18 at 3:46
post the code so we can help
– John Joe
Nov 13 '18 at 3:46
1
1
This sounds like homework.
– majidarif
Nov 13 '18 at 6:05
This sounds like homework.
– majidarif
Nov 13 '18 at 6:05
I figured it out and yes this is an assignment.
– FrancoMedicci
Nov 14 '18 at 0:32
I figured it out and yes this is an assignment.
– FrancoMedicci
Nov 14 '18 at 0:32
add a comment |
3 Answers
3
active
oldest
votes
You could use Collections.min
:
List<Integer> numbers = new ArrayList<>()
numbers.add(...) // parse your text to int
int minimum = Collections.min(numbers);
add a comment |
First, you have to get values from 4 EditText, then parse String to Int
int num1, num2, num3, num4;
try {
num1 = Integer.parseInt(editText1.getText().trim().toString());
num2 = Integer.parseInt(editText2.getText().trim().toString());
num3 = Integer.parseInt(editText3.getText().trim().toString());
num4 = Integer.parseInt(editText4.getText().trim().toString());
} catch (Exception e) {
// Handle error here
}
You can easily find min from the integers then
textView.setText(String.valueOf(min))
add a comment |
min.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Integer> numbers = new ArrayList<>();
numbers.add(Integer.parseInt(editText1.getText().trim().toString()));
numbers.add(Integer.parseInt(editText2.getText().trim().toString()));
numbers.add(Integer.parseInt(editText3.getText().trim().toString()));
numbers.add(Integer.parseInt(editText4.getText().trim().toString()));
min.setText(String.valueOf(Collections.min(numbers)));}
});
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273358%2fhow-to-calculate-min-value-of-4-edittexts-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could use Collections.min
:
List<Integer> numbers = new ArrayList<>()
numbers.add(...) // parse your text to int
int minimum = Collections.min(numbers);
add a comment |
You could use Collections.min
:
List<Integer> numbers = new ArrayList<>()
numbers.add(...) // parse your text to int
int minimum = Collections.min(numbers);
add a comment |
You could use Collections.min
:
List<Integer> numbers = new ArrayList<>()
numbers.add(...) // parse your text to int
int minimum = Collections.min(numbers);
You could use Collections.min
:
List<Integer> numbers = new ArrayList<>()
numbers.add(...) // parse your text to int
int minimum = Collections.min(numbers);
answered Nov 13 '18 at 3:39
Aaron
1,6831212
1,6831212
add a comment |
add a comment |
First, you have to get values from 4 EditText, then parse String to Int
int num1, num2, num3, num4;
try {
num1 = Integer.parseInt(editText1.getText().trim().toString());
num2 = Integer.parseInt(editText2.getText().trim().toString());
num3 = Integer.parseInt(editText3.getText().trim().toString());
num4 = Integer.parseInt(editText4.getText().trim().toString());
} catch (Exception e) {
// Handle error here
}
You can easily find min from the integers then
textView.setText(String.valueOf(min))
add a comment |
First, you have to get values from 4 EditText, then parse String to Int
int num1, num2, num3, num4;
try {
num1 = Integer.parseInt(editText1.getText().trim().toString());
num2 = Integer.parseInt(editText2.getText().trim().toString());
num3 = Integer.parseInt(editText3.getText().trim().toString());
num4 = Integer.parseInt(editText4.getText().trim().toString());
} catch (Exception e) {
// Handle error here
}
You can easily find min from the integers then
textView.setText(String.valueOf(min))
add a comment |
First, you have to get values from 4 EditText, then parse String to Int
int num1, num2, num3, num4;
try {
num1 = Integer.parseInt(editText1.getText().trim().toString());
num2 = Integer.parseInt(editText2.getText().trim().toString());
num3 = Integer.parseInt(editText3.getText().trim().toString());
num4 = Integer.parseInt(editText4.getText().trim().toString());
} catch (Exception e) {
// Handle error here
}
You can easily find min from the integers then
textView.setText(String.valueOf(min))
First, you have to get values from 4 EditText, then parse String to Int
int num1, num2, num3, num4;
try {
num1 = Integer.parseInt(editText1.getText().trim().toString());
num2 = Integer.parseInt(editText2.getText().trim().toString());
num3 = Integer.parseInt(editText3.getText().trim().toString());
num4 = Integer.parseInt(editText4.getText().trim().toString());
} catch (Exception e) {
// Handle error here
}
You can easily find min from the integers then
textView.setText(String.valueOf(min))
answered Nov 13 '18 at 4:33
Liar
858514
858514
add a comment |
add a comment |
min.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Integer> numbers = new ArrayList<>();
numbers.add(Integer.parseInt(editText1.getText().trim().toString()));
numbers.add(Integer.parseInt(editText2.getText().trim().toString()));
numbers.add(Integer.parseInt(editText3.getText().trim().toString()));
numbers.add(Integer.parseInt(editText4.getText().trim().toString()));
min.setText(String.valueOf(Collections.min(numbers)));}
});
add a comment |
min.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Integer> numbers = new ArrayList<>();
numbers.add(Integer.parseInt(editText1.getText().trim().toString()));
numbers.add(Integer.parseInt(editText2.getText().trim().toString()));
numbers.add(Integer.parseInt(editText3.getText().trim().toString()));
numbers.add(Integer.parseInt(editText4.getText().trim().toString()));
min.setText(String.valueOf(Collections.min(numbers)));}
});
add a comment |
min.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Integer> numbers = new ArrayList<>();
numbers.add(Integer.parseInt(editText1.getText().trim().toString()));
numbers.add(Integer.parseInt(editText2.getText().trim().toString()));
numbers.add(Integer.parseInt(editText3.getText().trim().toString()));
numbers.add(Integer.parseInt(editText4.getText().trim().toString()));
min.setText(String.valueOf(Collections.min(numbers)));}
});
min.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Integer> numbers = new ArrayList<>();
numbers.add(Integer.parseInt(editText1.getText().trim().toString()));
numbers.add(Integer.parseInt(editText2.getText().trim().toString()));
numbers.add(Integer.parseInt(editText3.getText().trim().toString()));
numbers.add(Integer.parseInt(editText4.getText().trim().toString()));
min.setText(String.valueOf(Collections.min(numbers)));}
});
answered Nov 13 '18 at 7:01
Dharm solanki
66
66
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273358%2fhow-to-calculate-min-value-of-4-edittexts-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what have you tried ? Have you successfully get the text from editText ?
– John Joe
Nov 13 '18 at 3:29
I figured out that part. i'm stuck in getting the result and showing it in the textview.
– FrancoMedicci
Nov 13 '18 at 3:46
post the code so we can help
– John Joe
Nov 13 '18 at 3:46
1
This sounds like homework.
– majidarif
Nov 13 '18 at 6:05
I figured it out and yes this is an assignment.
– FrancoMedicci
Nov 14 '18 at 0:32