Ako môžem zjednodušiť celý tento kód? Ja som vytváranie vyhľadávanie menu a chcem zistiť hodnotami, keď používateľ opustí "Text Zobraziť" a zobrazí výstup okamžite ako "Recyklovať Viewer" nižšie.
Jeden spôsob, ako je to s veľmi veľký počet Investičných fondov. Navrhujete iný spôsob?
Používam Roon Knižnica pre svoju aplikáciu, databázu.
Chcel som použiť tento kód za to, ale videl som, že počet IFs je veľmi vysoká.
Priateľ navrhol, pomocou Prípade v databáze, ale neviem, ako napísať jeho kód!
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) { } }
Tiež som chcela napísať dotaz pomocou Prípade, ale nepodarilo sa. To bol kód napísal som
@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);
Aj keď som bol veľmi hľadaní vhodného riešenia, I, bohužiaľ, nemohli ho nájsť.
Vopred vám ďakujeme za vašu pomoc.