I can't go through the word-in-the-record search in ActionBar Android.



  • I'm writing a museum. ListView (I've got an infa View contained in ArrayList < HashMap < String, Object > >)
    In one line ListView I'm pulling out three lines.

    I have a work code that's looking for one parameter, and I need a search to be done three times at the same time.
    For example, the line on the list, "the name of the track, the name of the performer, the name of the album" needs to be found on either the name of the track or the name of the album or the name of the perpetrator. The work code is attached.

     String searchString = searchBox.getText().toString();
                int textLength = searchString.length();
                listSongsForlistViewMainActivity.clear();
    
            for (int i = 0; i &lt; listSongs.size(); i++) {
                String playerName = listSongs.get(i).get("songName").toString();// тут что укажу, по тому параметру и ищет
                if (textLength &lt;= playerName.length()) {
                    //compare the String in EditText with Names in the ArrayList
                    if (searchString.equalsIgnoreCase(playerName.substring(0, textLength)))
                        listSongsForlistViewMainActivity.add(listSongs.get(i));
                }
            }
    
            adapterForListViewMainActivity.notifyDataSetChanged();
    



  • Like this:

            for (int i = 0; i < listSongs.size(); i++) {
                String songName = listSongs.get(i).get("songName").toString();
                String albumName = listSongs.get(i).get("albumName").toString();
                String artistName = listSongs.get(i).get("artistName").toString();
    
                if (searchString.equalsIgnoreCase(songName.substring(0, textLength)) || searchString.equalsIgnoreCase(albumName.substring(0, textLength)) || searchString.equalsIgnoreCase(artistName.substring(0, textLength)))
                    listSongsForlistViewMainActivity.add(listSongs.get(i));
            }
    

    I mean, we get all three rows to search and compare them by logical OR - if one of the lines matches - the condition is true.

    PS: condition may be reduced if the condition is removed

    It's done. http://blog.nkdroidsolutions.com/android-searchview-in-listview-example-tutorial/




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2