0

I have a list view and i want to show records by filter suppose i have an array list called expenseList. in expenseList i am able to filter single item like this

 if (!dealerexpautoa.getText().toString().equals("")){
                        ArrayList<ExpenseStatusModel.Expense> expensetypeList= new ArrayList<>();

                        for (int i = 0; i < expenseList.size(); i++)
                        {
                            if (expenseList.get(i).getDealerName().equalsIgnoreCase(dealerexpautoa.getText().toString())) {

                                expensetypeList.add(expenseList.get(i));
                            }
                        }
                        adapterExpenseView.filterList(expensetypeList);

                    }

here getting the perfect output but when i need to perform same task with two string then it is not getting me the right out put

i have an EditText and Spinner i want to compare both and print in list view

else if(!spn.getSelectedItem().toString().equals("Select Type")
                            && !dealerexpautoa.getText().toString().equals("")){
                        ArrayList<ExpenseStatusModel.Expense> expensetypeList= new ArrayList<>();

                        for (int i = 0; i < expenseList.size(); i++)
                        {
                            if (expenseList.get(i).getDealerName().equalsIgnoreCase(dealerexpautoa.getText().toString()) &&
                                    expenseList.get(i).getExpenseType().equalsIgnoreCase(spn.getSelectedItem().toString())) {

                                expensetypeList.add(expenseList.get(i));
                            }
                        }
                        adapterExpenseView.filterList(expensetypeList);

                    }

2 Answers 2

1

The condition expression in if branch is:

!dealerexpautoa.getText().toString().equals("")  

and the condition expression in else branch is

!spn.getSelectedItem().toString().equals("Select Type")
                            && !dealerexpautoa.getText().toString().equals("")

this two expressions are not mutually exclusive, only dealerexpautoa text is equal empty string, it could enter into else branch, but in else branch,the condition needs dealerexpautoa text not equal empty string, so this is contradictory.

Sign up to request clarification or add additional context in comments.

2 Comments

so how to perform this task any example? i know that only first condition is checked by if... but the thing is i show this code for how i tried
unclear total login, try using two independent if clause, no else branch.
1

you forgot to write if in your else statement

else if(!spn.getSelectedItem().toString().equals("Select Type")
                            && !dealerexpautoa.getText().toString().equals("")){
                        ArrayList<ExpenseStatusModel.Expense> expensetypeList= new ArrayList<>();

                        for (int i = 0; i < expenseList.size(); i++)
                        {
                            if (expenseList.get(i).getDealerName().equalsIgnoreCase(dealerexpautoa.getText().toString()) &&
                                    expenseList.get(i).getExpenseType().equalsIgnoreCase(spn.getSelectedItem().toString())) {

                                expensetypeList.add(expenseList.get(i));
                            }
                        }
                        adapterExpenseView.filterList(expensetypeList);

                    }

1 Comment

i am sorry i forgot to write if in the question but actually in my project it is else if only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.