[英]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.