을 구축하는 방법과 단순화 Java 코드 for 안드로이드

0

질문

할 수 있는 방법을 간소화 이 모든 코드? 내가 만드 검색 메뉴를 확인하고 싶어 하는 경우 값이 사용자가 종료하는'텍스트보기'와 출력이 표시 즉시로'휴지 뷰어'다.

  • 한 가지 방법은 이와 함께 매우 많은 수의 IFs. 당신은 제안 다른 방법이 있나요?

  • 내가 사용하는 Roon 라이브러리를 위한 내 응용 프로그램 데이터베이스입니다.

나는 원하는 이 코드를 사용하려면 이를 위해 그러나 나는 수 IFs 이 매우 높습니다.

  • 친구를 사용하여 제안 경우에 데이터베이스,하지만 작성하는 방법을 알고 그들을 훈련합니다.

         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) {
    
         }
     }
    
  • 저는 또 쓰고 싶다는 쿼리를 사용하는 경우이지만 실패했습니다. 이 코드는 내가 쓴

     @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);
    

이었지만 아주 많이 찾는 올바른 솔루션을,저는 불행하게도 그것을 찾을 수 없습니다.

사전에 감사합니다 당신의 도움이됩니다.

Form Image

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

작업필,TraderName,SearchBy 모두 같은 회전. 어디에 얻고 있는 데이터를 채우기 옵션이 있습니다. 는 경우에는 그것의 하드 응용 프로그램 방법에 따라 구현할 가능성이 그들이 비어 있기 때문에 항상 기본 옵션을 선택합니다. 할 수 있습을 확인할 필요가 없을 경우 그들은 비어 있습니다. 당신은 대부분야에 초점을 맞추고 보고서로 종료 Edittexts. 할 수 있음을 사용하여 날짜 선택다.

2021-11-24 00:13:17
0

I 단축 그것은 당신을위한,이것은 그것을 할 수있는 가장 좋은 방법은 있지만 그것은 여전히 작동

나의 짧은 버전 하지만 그것은 약간의 시간이 걸릴 것이 있을 것이기 때문에 더 복잡하게 만듭니다:

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

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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