【发布时间】:2018-12-03 02:11:53
【问题描述】:
我有一个名为 Inputs1 的“EditText”,用于输入值以使用“If”语句与数组 example1 进行比较。
名为 example1 的数组具有以下值:5、10、15、20、25、30
Outputs1 用于显示来自数组example1的值
此外,名为 example2 的数组具有以下值:105、110、115、120、125、130
Outputs2 用于使用数组example1 中的索引值显示数组example2 中的值
例子:
Inputs1的值为:20
Outputs1显示值:20
Outputs2应该显示值:120
我什至让Outputs1 显示值:20,但我无法获得Outputs2 的代码来显示值:120。
请有上述经验或知识的人帮助我?
谢谢。
代码:
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("");
}
}
}
【问题讨论】:
-
请发布您的代码,了解如何获得 Label1 的价值
-
你当前的密码是多少?
标签: java android arrays if-statement indexing