开发者

Filtering list view gives incorrect results [closed]

开发者 https://www.devze.com 2023-03-24 11:41 出处:网络
开发者_运维问答 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely so
开发者_运维问答 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

If something does not make sense please let me know. I am aware my questions are not always precise.

I have a listview that I am trying to filter by name. I have an EditText field, which users type in to filter the listview. The toString in the DirectoryListing class is overridden, allowing for correct comparisons.

Here is the problem: Say I have the following, each in their own row in the listview: "AC, BC, CD, AE". Now in the edit text field, if B is entered, the listview displays, "AC". A will display AC, BC. As you can see it will show the amount of items that match what was entered, but it just displays the approriate amount from the top down, not the correct items. Any idea what I am doing wrong? Here is my code.

//imports and some variable declaration
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.directory);
        final Handler handler = new Handler() {
            //fill the listview to start
            }

        };
        listing = new ArrayList<DirectoryListing>();
        this.adapter = new DirectoryAdapter(this, R.layout.dir_rows, listing);
        setListAdapter(adapter);
        ProgressDialog = ProgressDialog.show(DirectoryActivity.this, "Please wait...", "Retrieving data ...", true);
        viewOrders = new Runnable() {
            //execute filling the original listview
        };
        TextWatcher filterTextWatcher = new TextWatcher() {

            public void afterTextChanged(Editable s) {
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                adapter.getFilter().filter(s);
                adapter.notifyDataSetChanged();
            }

        };

        filterText = (EditText) findViewById(R.id.search_box);
        filterText.addTextChangedListener(filterTextWatcher);
        Thread thread = new Thread(null, viewOrders, "Background");
        thread.start();

    }
    //other code

}

0

精彩评论

暂无评论...
验证码 换一张
取 消