Jak mogę uprościć cały ten kod? Tworzę menu wyszukiwania i chcę sprawdzić wartości, gdy użytkownik wychodzi z "Tekstu w widoku", i natychmiast wyświetlać w postaci "podglądu" poniżej.
Jednym ze sposobów, aby to zrobić z bardzo dużą ilością "jeśli". Proponujesz inna metoda?
Używam biblioteki Roon do swojej bazy danych aplikacji.
Chciałem użyć do tego ten kod, ale zobaczył, że liczba "Jeśli" jest bardzo duża.
Przyjaciel zaproponował użyć handlowego w bazie danych, ale nie wiem jak napisać kod!
public void searchHelper() { String sOperationValue = spinnerOperation.getText().toString(); String sTraderValue = spinnerTraderName.getText().toString(); String sSearchByValue = spinnerSearchBy.getText().toString(); long startValue = Long.parseLong(etStartDate.getText().toString()); long endValue = Long.parseLong(etEndDate.getText().toString()); // * * * * * if (!sOperationValue.isEmpty() && !sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // * - * * * if (!sOperationValue.isEmpty() && sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // * - - - - if (!sOperationValue.isEmpty() && sTraderValue.isEmpty() && sSearchByValue.isEmpty() && startValue <= 0 && endValue <= 0) { } // - * * * * if (sOperationValue.isEmpty() && !sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // Here 'Search By' specifies whether the search should be based on the date of registration or on the date of the transaction. // Therefore, when Search By is empty, then the start date and end date values are also empty. // - * - - - if (sOperationValue.isEmpty() && !sTraderValue.isEmpty() && sSearchByValue.isEmpty() && startValue <= 0 && endValue <= 0) { } // - - * * * if (sOperationValue.isEmpty() && sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // - - - - - if (sOperationValue.isEmpty() && sTraderValue.isEmpty() && sSearchByValue.isEmpty() && startValue <= 0 && endValue <= 0) { } }
Chciałem też napisać zapytanie z użyciem liter, ale nie mógł. To był kod, który napisałem
@Query("SELECT * FROM tbl_transaction" + " WHERE CASE WHEN operation='null'" + " THEN CASE WHEN traderName='null'" + " THEN CASE WHEN transactionType ='null'" + " THEN CASE WHEN startDate=14000000" + " THEN CASE WHEN endDate=15000000" ) List<Transaction> getSearchValues(String operation, String traderName, String transactionType, long startDate, long endDate);
Mimo, że jestem bardzo mocno szukałem właściwą decyzję, ja niestety nie mogłem go znaleźć.
Z góry dziękuję za pomoc.