public class MainActivity extends AppCompatActivity {
Button button;
EditText fruits;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerButton();
}
private void addListenerButton() {
fruits=(EditText)findViewById(R.id.editText);
button=(Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(fruits.getText().toString().equals("orange")||fruits.getText().toString().equals("aple")||fruits.getText().toString().equals("grape")){
Intent clicked=new Intent(MainActivity.this,Main2Activity.class);
startActivity(clicked);
}else {
Toast.makeText(getBaseContext(),"Error!",Toast.LENGTH_LONG).show();
}
}
});
}
}
if(fruits.getText().toString().equals("orange")||fruits.getText().toString().equals("aple")||fruits.getText().toString().equals("grape"))
帮助我,我想制作100个水果名称:你能让这更容易吗?我希望你帮我使用数组列表。非常感谢!
答案 0 :(得分:0)
String[] terms = {"orange", "apple", "grape"};
if (Arrays.asList(terms).contains(fruits.getText().toString())) {
// start your activity
}