在我的android應用程序中,我測試了一些字符串(我從另一個活動中獲取)以查看它們是否爲空。如果沒有,我建我的網址,從這些值,例如:(編者)多重值測試,如何替換許多其他if語句?
//country only
if (!fetchData_country.isEmpty() && fetchData_city.isEmpty() && fetchData_pmin.isEmpty() && fetchData_pmax.isEmpty()){
query_url = URL_PRODUCT + "?" + URL_SEARCH_COUNTRY + id_country + URL_LANGUAGE;
Log.i("INFO", "Url country only : " + query_url);
}
//country & price min
else if(!fetchData_country.isEmpty() && fetchData_city.isEmpty() && !fetchData_pmin.isEmpty() && fetchData_pmax.isEmpty()) {
query_url = URL_PRODUCT + "?" + URL_SEARCH_COUNTRY + id_country + "&" + URL_SEARCH_PRICE_MIN + id_pmin + URL_LANGUAGE;
Log.i("INFO", "Url country & price_min : " + query_url);
}
//city & price_min
else if(fetchData_country.isEmpty() && !fetchData_city.isEmpty() && !fetchData_pmin.isEmpty() && fetchData_pmax.isEmpty()) {
query_url = URL_PRODUCT + "?" + URL_SEARCH_CITY + id_city + "&" + URL_SEARCH_PRICE_MIN + id_pmin + URL_LANGUAGE;
Log.i("INFO", "Url city & price_min : " + query_url);
}
// country & city & pmin
else if(!fetchData_country.isEmpty() && !fetchData_city.isEmpty() && !fetchData_pmin.isEmpty() && fetchData_pmax.isEmpty()) {
query_url = URL_PRODUCT + "?" + URL_SEARCH_COUNTRY + id_country + "&" + URL_SEARCH_CITY + id_city + "&" + URL_SEARCH_PRICE_MIN + id_pmin + URL_LANGUAGE;
Log.i("INFO", "Url country & city & pmin : " + query_url);
}//many values to test still...
我不知道我怎樣才能提高這些測試的部分,感謝您的幫助!
@Palcenteü可以開發一個小PLS?這不是很清楚,謝謝 – Jay
!fetchData_pmin.isEmpty()&& fetchData_pmin.isEmpty()這根本沒有意義 –
@NongthonbamTonthoi,sorry!fetchData_pmin.isEmpty()&& fetchData_pmax.isEmpty(),除此之外,我的代碼工作,我正在尋找改進,同時測試thx(代碼編輯) – Jay