I have an “EditText” called Inputs1 to enter values to compare with the Array example1 using an “If” statement.
The Array named example1 has these values: 5 , 10, 15, 20, 25, 30
Outputs1 is used to display values from the Array example1
Also, an Array named example2 have these values: 105, 110, 115, 120, 125, 130
Outputs2 is used to display values from the Array example2 using the index value from the Array example1
Example:
The
Inputs1value is: 20
Outputs1displays the value: 20
Outputs2should display the value: 120
I went as far as making Outputs1 to display the value: 20, but I cannot get the code for Outputs2 to display the value: 120.
Please, anyone with the above experience or knowledge help me?
Thanks.
Code:
public class exampleOutput extends AppCompatActivity {
Editable text;
EditText Inputs1;
TextView Outputs1;
TextView Outputs2;
Integer arrayIndex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example_output);
Outputs1 = (TextView) findViewById(R.id.Outputs1);
Inputs1 = (EditText) findViewById(R.id.Inputs1);
text = Inputs1.getText();
Outputs2 = (TextView) findViewById(R.id.Outputs2);
}
final String[] example1 = {("5"), ("10"), ("15"), ("20"), ("25"), ("30")};
final String[] example2 = {("105"), ("110"), ("115"), ("120"), ("125"), ("130")};
public void displayExample(View v) {
if (Arrays.asList(example1).contains(Inputs1.getText().toString())) {
Outputs1.setText("You typed in: " + text + ", which is correct!");
arrayIndex = (Arrays.asList(example1).indexOf(Inputs1.getText().toString()));
Outputs2.setText("Your second number is: [The value from the second array] " + ", the index is: " + arrayIndex + "!");
} else {
Outputs1.setText("Please type in a number 1-5.");
Outputs2.setText("");
}
}
}