[英]How to check AutoCompleteTextView if it contains text?
我在用户应填写的片段中有两个AutoCompleteTextView。 然后,必须将这两个字符串值发送到其他活动,否则(如果未填写)您应该看到敬酒。 我尝试实现它,但是不起作用:
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();
}
}
而不是检查(originAddress!=“”),请使用isEmpty()方法。
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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.