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 8886689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:37:08+00:00 2026-06-14T21:37:08+00:00

I’ve been searching the web for a few day’s (actually nights ;), but at

  • 0

I’ve been searching the web for a few day’s (actually nights ;), but at the moment I’m very stuck in finding a solution for my problem. Basically what I want is a listview of SQLite, with filter and the important thing: keeping the list-row result consistent with the SQLite row’s.

I’ve started easy with a basic listview, but it wasn’t possible to keep consistency between the SQLite row’s and the filtered listview.
Then I moved on to a simplecursor, but I never get a filtered result, only the complete SQLite list is being showed.

I think I’m missing something in the direction of telling the SimpleCursorAdapter to refresh with the filtering. I’ve found a lot of pages with some pieces of code, but can’t seem to implement it in my own code. It has to do with: setFilterQueryProvider ( I think)
Also I’ve read this SimpleCursorAdapter is now obsolete and moves to loaders?
Let me get this one step at a time, so hopefully with a bit of help I can get this filtering to work an move on to loaders.

Thank you for taking the time and read my code. As it’s now almost 5 o clock in the morning, I hope my English is still okay 🙂

public class MainActivity extends Activity {
    String TAG = "MainActivity";            // for logging purposes
    private ArrayList<String> data;         // location which receives all products to display in the list
    static int ProductCursorPosition;       // the id which will returned by pressing the listview
    private ListView listView_Products;             // define the listview variabele
    SimpleCursorAdapter adapter;
    EditText inputSearch;

public void  onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    
    setContentView(R.layout.act_main);
    Log.v(TAG, "onCreate");
 //   Worker dbworker = new Worker(this.getApplicationContext());
//  Log.v(TAG,"Open database");
//  dbworker.open();
//  Log.v(TAG,"Get database entry's");           
//  data = dbworker.getProductListView(); 
//  dbworker.close();
}

@Override
protected void onResume() {
    super.onResume();
    Log.v(TAG, "onResume");
    displayListView();          // show me the products in the listview
    aantalbestellingen();       // update the total numbers of bread waiting in order
}

// display the listview with products
public void displayListView() {
    Log.v(TAG,"Select database");
    Worker dbworker = new Worker(this.getApplicationContext());
    Log.v(TAG,"Open database");
    dbworker.open();
    String[] columns = new String[]{ Worker.KEY_ROWID, Worker.KEY_PRODUCT};
    String[] from = new String[]{Worker.KEY_PRODUCT};

    int [] to = {R.id.text1};
    final Cursor cursor = Worker.ourDatabase.query(true, // isdistinct
            Worker.DB_TABLE_PROD, // table name
            columns,// select clause
            null, // where cluase
            null, // where clause parameters
            null, // group by
            null, // having
            null, // nogwat 
            null);// limit
    startManagingCursor(cursor);


    adapter = new SimpleCursorAdapter(this, R.layout.lv_customlayout01, cursor, from, to);

    // find the view for the listview and connect the listView_Products to it
    listView_Products = (ListView) findViewById(R.id.lvProducts);
    // Shows the adapter content in the listview
    listView_Products.setAdapter(adapter);  

    dbworker.close();


    /**
     * Enabling Search Filter
     * */
    inputSearch = (EditText) findViewById(R.id.etSearchbar); 
    inputSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            Log.v(TAG,"Filter: onTextChanged");
            Log.v(TAG,"Filterstring: " + cs);
            Log.v(TAG,"adapter: " + adapter);
            adapter.getFilter().filter(cs); 
//          adapter.getFilter().filter(cs.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            Log.v(TAG,"Filter: beforeTextChanged");
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
            Log.v(TAG,"Filter: afterTextChanged");
//          adapter.notifyDataSetChanged();

        }
    });


    listView_Products.setOnItemClickListener( new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        Log.v(TAG, "Pressed the listview\n" + 
        "View arg2 = " + arg2 + "\n" +
        "int arg3 = " + arg3 + "\n");   
    }
    });

}

}

Ok, I’ve changed the code a bit:
Now I’m having a listview with filter results.

// display the listview with products
public void displayListView() {
    Log.v(TAG,"DB select");
    Worker dbworker = new Worker(this.getApplicationContext());
    Log.v(TAG,"DB open");
    dbworker.open();

    // SQLite get cursor from Worker 
    final Cursor ItemCursor = Worker.cursorsetup01();
    // Start managing the cursor
    startManagingCursor(ItemCursor);

    // Columns to be bound to the adapter
        String[] FROMcolumns = new String[]{Worker.KEY_PRODUCT, Worker.KEY_INFO };
        // THE XML DEFINED VIEWS WHICH THE DATA WILL BE BOUND TO
        int[] ToXMLView = new int[] {R.id.tvProduct, R.id.tvProductInfo};
        // CREATE THE ADAPTER USING THE CURSOR POINTING TO THE DESIRED DATA AS WELL AS THE LAYOUT INFORMATION

        Log.v(TAG,"CREATE THE ADAPTER");    
        adapter = new SimpleCursorAdapter(this, R.layout.lv_customlayout01, ItemCursor, FROMcolumns, ToXMLView);
        // find the view for the listview and connect the listView_Products to it

        listView_Products = (ListView) findViewById(R.id.lvProducts);
        // SET THIS ADAPTER AS YOUR LISTACTIVITY'S ADAPTER
        listView_Products.setAdapter(adapter);      

    adapter.setFilterQueryProvider(new FilterQueryProvider() {

        public Cursor runQuery(final CharSequence substring) {
            String[] dbquerycolumns = new String[]{Worker.KEY_PRODUCT, Worker.KEY_INFO, Worker.KEY_ROWID };    
            Worker dbworker = new Worker(getApplicationContext());
            Log.v(TAG,"Open database");
            dbworker.open();
            return Worker.ourDatabase.query(
                            Worker.DB_TABLE_PROD, // TABLE
                            dbquerycolumns,// COLUMNS
                            "product LIKE '%" + substring.toString() + "%'" , // SELECTION
                            null, // SELECTION ARGS
                            null, // GROUP BY
                            null, // HAVING
                            "_id LIMIT 100");// ORDER BY (limit the results to 100)
                    }

        });


    // Connect the textedit searchbar to a change listener and action upon changes
    mySearchText = (EditText)findViewById (R.id.etSearchbar);
    mySearchText.addTextChangedListener (new TextWatcher() {

        @Override
        public void afterTextChanged (Editable s) {
            Log.v(TAG,"Textchanged: AfterTextChanged: " + s);
            adapter.getFilter().filter(s.toString());
            startManagingCursor(ItemCursor);
        }
  • 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-14T21:37:09+00:00Added an answer on June 14, 2026 at 9:37 pm

    Couple of things that would help you

    1. Loader ( or one from support) to resolve the consistency issues
    2. A full implementation of Custom Adapter – rather than a pre packaged one – for managing and keeping up with the updates that are happening with the EditText

    Now, couple of things that you would have to amend to your existing code.

    1. Maintain an old instance of the data that is Loaded from dataBase – you would always need to use it to checkback – Collection1
    2. Maintain a similar collection which is shown to UI through the Custom Adapter – Collection2
    3. When text in the EditText changes – (A) remove the entries of Collection2 and recreate it using the new filter (b) create a new instance of the Adapter with the latest collection2 (c) set this new instance to the listView (d) recycle the old instance for optimization

    This, way your updates will be instantaneous to the user, while you would have the full control in resolving your current issues as well as any that might come.

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I have been unable to fix a problem with Java Unicode and encoding. The
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms

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.