Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检查AutoCompleteTextView是否包含文本?_Java_Android_Autocomplete - Fatal编程技术网

Java 如何检查AutoCompleteTextView是否包含文本?

Java 如何检查AutoCompleteTextView是否包含文本?,java,android,autocomplete,Java,Android,Autocomplete,我有两个用户应该填写的自动完成文本视图片段。然后,必须将这两个字符串值发送到其他活动,否则(如果没有填充),您应该看到一个toast。我试图实现它,但它不起作用: public void onFindPathClick(View view) { String originAddress = OriginPlaceFragment.mAutoPlaceSearch.getText().toString(); String destinationAddress = Destinati

我有两个用户应该填写的自动完成文本视图片段。然后,必须将这两个字符串值发送到其他活动,否则(如果没有填充),您应该看到一个toast。我试图实现它,但它不起作用:

public void onFindPathClick(View view) {
    String originAddress = OriginPlaceFragment.mAutoPlaceSearch.getText().toString();
    String destinationAddress = DestinationPlaceFragment.mAutoPlaceSearch.getText().toString();

    Intent intent = new Intent(SimpleTabsActivity.this, MapsActivity.class);
    if ((originAddress != "") && (!originAddress.equals(null)) && (destinationAddress != "") && (!destinationAddress.equals(null))) {
        intent.putExtra(ORIGIN_ADDRESS, originAddress);
        intent.putExtra(DESTIN_ADDRESS, destinationAddress);
        startActivity(intent);
    } else {
        Toast.makeText(this, "Fill \"from\" and \"to\" fields", Toast.LENGTH_SHORT).show();
    }
}
使用isEmpty()方法代替检查(originAddress!=“”)


如果出现异常,会发生什么。我希望onFindPathClick绑定到一个事件?
public void onFindPathClick(View view) {
String originAddress = OriginPlaceFragment.mAutoPlaceSearch.getText().toString();
String destinationAddress = DestinationPlaceFragment.mAutoPlaceSearch.getText().toString();

Intent intent = new Intent(SimpleTabsActivity.this, MapsActivity.class);
if (!originAddress.toString().isEmpty() && !destinationAddress.toString().isEmpty()) {
    intent.putExtra(ORIGIN_ADDRESS, originAddress);
    intent.putExtra(DESTIN_ADDRESS, destinationAddress);
    startActivity(intent);
} else {
    Toast.makeText(this, "Fill \"from\" and \"to\" fields", Toast.LENGTH_SHORT).show();
}
}