할 수 있는 방법을 간소화 이 모든 코드? 내가 만드 검색 메뉴를 확인하고 싶어 하는 경우 값이 사용자가 종료하는'텍스트보기'와 출력이 표시 즉시로'휴지 뷰어'다.
한 가지 방법은 이와 함께 매우 많은 수의 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);
이었지만 아주 많이 찾는 올바른 솔루션을,저는 불행하게도 그것을 찾을 수 없습니다.
사전에 감사합니다 당신의 도움이됩니다.