Search list in our android app?

Hi, there is a list view and a search section in my application. What I need to do, when I search for a word in the search section, it should sort the corresponding list according to the word I found. code to sort the name, but my real problem is that I need to search for a word, for example, I need to search

Ramz super

which is the only name in my current code, I need to search, like from R, then A, etc. in the correct order to sort the name. But I need me to start the search from Super I need to show the name Ramz super in listview. How can I do this, my current search code is shown below

    search_sort.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            // Abstract Method of TextWatcher Interface.
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // Abstract Method of TextWatcher Interface.
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            textlength = search_sort.getText().length();
            array_sort.clear();
            contactnumber_sort.clear();
            for (int i = 0; i < contactname.size(); i++) {
                if (textlength <= contactname.get(i).length()) {
                    if (search_sort.getText()
                            .toString()
                            .equalsIgnoreCase(
                                    (String) contactname.get(i).subSequence(
                                            0, textlength))) {
                        array_sort.add(contactname.get(i));
                        contactnumber_sort.add(contactnumber.get(i));
                    }
                }
            }
            System.out.println(array_sort);

            myadp = new myAdapter(MobiMailActivity.this, array_sort, contactnumber_sort);
            contactlist.setAdapter(myadp);
        }
    });
0
source
1

contains() equalsIgnoreCase().Where datasetList ArrayList<ContactList>.

  public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        String getSearchString = search.getText().toString();

        if(datasetList != null && datasetList.size() > 0)
        {
            sortedList = new ArrayList<ContactDataSet>(); //new List sorted list 

            for (int i = 0; i < datasetList.size(); i++) {

                if (datasetList.get(i).getName().contains(getSearchString)) {
                    sortedList.add(datasetList.get(i));

                }
            }
        }           
        adapter.setnewList(sortedList);
        lView.setAdapter(adapter);

    }

. . , .

+1

All Articles