我有两个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();
}
}
答案 0 :(得分:0)
而不是检查(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();
}
}