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