Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8375393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:09:53+00:00 2026-06-09T15:09:53+00:00

I tried this code but it’s too time-taking to iterate through all the list

  • 0

I tried this code but it’s too time-taking to iterate through all the list item.
item_all is a list which contains data I got from the database.

et_Search.addTextChangedListener(new TextWatcher() {

    int textlength;
    long time = System.currentTimeMillis();

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        textlength = getSearchText().length();

        item_filtered = new ArrayList<StockItem>();
        long time = System.currentTimeMillis();

        int i = 0;

        do {
            int startpost = 0;
            int endpost = textlength;
            boolean found;
            do {
                found = false;
                if (getItemDesc(i).length() >= textlength 
                    && getSearchText().equalsIgnoreCase((String)getItemDesc(i).subSequence(startpost, endpost))) {
                    item_filtered.add(item_all.get(i));
                    found = true;
                }

                startpost++;
                endpost++;
            } while (endpost <= getItemDesc(i).length() && !found);

            i++;
        } while ((i < item_all.size()) && (item_filtered.size() <= 20));

        Log.v("Time", "Time needed " + (System.currentTimeMillis() - time));

        if (item_filtered.isEmpty())
            AppendList(new ArrayList<StockItem>());
        else
            AppendList(item_filtered);
    }

then I tried to use LIKE

try {
    String[] WHATYOUWANT = { "*" };
    String WHERECLAUSE = KEY_DESCRIPTION + " LIKE '%" + textIinput + "%' " ;
    String GROUPBY = null;
    String HAVING = null;
    String ORDERBY = KEY_ROWID + " ASC LIMIT 0,100 ";

    cursor = mDb.query(DATABASE_TABLE, WHATYOUWANT, WHERECLAUSE, null, GROUPBY, HAVING, ORDERBY);

    } catch (Exception e) {
        e.printStackTrace();
}

It works great except but it does not really do what I want.

What I want is the searched item match exactly with the input. Aay I input “abc”, I don’t want items which contain only “ab” or “bc” (not “abc”) to appear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:09:54+00:00Added an answer on June 9, 2026 at 3:09 pm

    Try to use contains() instead of equalsIgnoreCase().

     if (getItemDesc(i).length() >= textlength
                                && getItemDesc(i)
                                        .contains(getSearchText()));
    

    This might help you. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this, but could not get through:- code behind protected HtmlTableRow trComment; protected
I tried to use this code but it doesn't work. http://developer.apple.com/library/ios/#samplecode/PageControl/Introduction/Intro.html Ld /Users/waitonza/Library/Developer/Xcode/DerivedData/Dr_Ngoo-aanknxmuodcgjicaigxevljxokeq/Build/Products/Debug-iphonesimulator/Dr Ngoo.app/Dr
i have tried this code to redirect a php page.but it s not working
i've tried using this code and this to make a random quote generator, but
I tried to understand this line of code, but it is failed. $this->request->{self::FLAG_SHOW_CONFIG} ===
I tried to compile Ercia Sadun's sample code here , but this error came
I tried this code but is not working .. protected void btnAbc_Click(object sender, EventArgs
i tried this code,but it is throwing error. Private Sub ClearText Dim ctl As
I want 'Duration' and 'Cost' Right aligned. I tried this code but it's not
I have tried this code but no data is lost from the listview when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.