【发布时间】:2016-08-29 05:09:14
【问题描述】:
我正在尝试创建一个应用程序来检查在 EditText 字段中输入的语句的条件。目前,我已经写了如果输入的单词是不区分大小写的“下一个”,然后按“博客”按钮进入下一个屏幕。
我的问题是如何编写“if”语句,以便如果在 EditText 字段中输入了一个短语,并且该短语的任何部分都包含“next”这个词,然后按“”进入下一页博客按钮?例如,如果输入短语“请转到下一页”,则“if”语句应该识别出不区分大小写的单词“next”,因此允许您通过按进入下一页“博客”按钮。
下面是需要修改的部分相关代码的sn-p:
public void onButtonClick(View v) {
if (v.getId() == R.id.Blogin) {
String str = a.getText().toString();
//Go to the next 'Display' window or activity if the person enters the correct username which is not case sensitive
if (str.equalsIgnoreCase("next")) {
Intent userintent = new Intent(MainActivity.this, Display.class);
startActivity(userintent);
} else {
Toast.makeText(getApplicationContext(), "Incorrect Information", Toast.LENGTH_SHORT).show();
}
}
}
【问题讨论】:
-
if (str.toLowerCase().contains("next")) -
@DanielNugent 的回答是正确的。
-
这两种方法都很好用,但 Daniel 你的方法最容易实现
标签: android listview android-studio android-intent android-edittext