Ako vybudovať a zjednodušiť Java kód pre Android

0

Otázka

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.

Form Image

android android-room database java
2021-11-23 22:09:06
2
0

OperationType, TraderName, SearchBy všetci vyzerajú ako Špirály. Ak sa vám darí údaje k naplneniu možnosti. Ak jej napevno do aplikácie v závislosti na tom, ako si uplatňovať svoje nepravdepodobné, že bude stále prázdne, pretože tam je vždy predvolená možnosť vybratá. Môžete, nie je potrebné skontrolovať, či sú prázdne. Potom sa väčšinou byť zamerané na startDate a endDate Edittexts. Potom môžete ďalej zlepšovať pomocou Dátum zberači miesto.

2021-11-24 00:13:17
0

Som skrátil to pre vás, to nie je najlepší spôsob, ako to urobiť, ale to ešte funguje

Budem robiť kratšia verzia, ale to bude trvať nejaký čas, pretože to bude zložitejšie, aby:

public void searchHelper() {
    boolean b1 = spinnerOperation.getText().toString()isEmpty();
    boolean b2 = spinnerTraderName.getText().toString()isEmpty();
    boolean b3 = spinnerSearchBy.getText().toString()isEmpty();
    boolean b4 = Long.parseLong(etStartDate.getText().toString()) >= 14000000 && Long.parseLong(etEndDate.getText().toString()) <= 15000000;
     boolean b5 = Long.parseLong(etStartDate.getText().toString()) <= 0 && Long.parseLong(etEndDate.getText().toString()) <= 0;

     // * * * * *
     if (!b1 && !b2 && !b3 && b4) {

     }
     // * - * * *
     if (!b1 && b2 && !b3 && b4) {

     }
     // * - - - -
     if (!b1 && b2 && b3 && b5) {

     }
     // - * * * *
     if (b1 && !b2 && !b3 && b4) {

     }
     // 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 (b1 && !b2 && b3 && b5) {

     }
     // - - * * *
     if (b1 && b2 && !b3 && b4) {

     }
  // - - - - -
    if (b1 && b2 && b3 && b5) {

  }
 }
2021-11-24 00:02:54

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................