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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:21:24+00:00 2026-06-03T09:21:24+00:00

Creating a searchable contacts kind of app. Below is my code public class EmployeeList

  • 0

Creating a searchable contacts kind of app. Below is my code

public class EmployeeList extends Activity {

    protected EditText searchText;
    protected SQLiteDatabase db;
    protected Cursor cursor, listcursor;
    protected ListAdapter adapter;
    protected ListView employeeList;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        db = (new DatabaseHelper(this)).getWritableDatabase();
        searchText = (EditText) findViewById (R.id.searchText);
        employeeList = (ListView) findViewById (R.id.list);

        listcursor = db.rawQuery("SELECT * FROM employee",null);

        adapter = new SimpleCursorAdapter(
                this, 
                R.layout.employee_list_item, 
                listcursor, 
                new String[] {"firstName", "lastName", "title"}, 
                new int[] {R.id.firstName, R.id.lastName, R.id.title});
        employeeList.setAdapter(adapter);
    }

        public void search(View view) {
            // || is the concatenation operation in SQLite
                    cursor = db.rawQuery("SELECT _id, firstName, lastName, title FROM employee WHERE firstName || ' ' || lastName LIKE ?", 
                                                    new String[]{"%" + searchText.getText().toString() + "%"});
                    adapter = new SimpleCursorAdapter(
                                    this, 
                                    R.layout.employee_list_item, 
                                    cursor, 
                                    new String[] {"firstName", "lastName", "title"}, 
                                    new int[] {R.id.firstName, R.id.lastName, R.id.title});
                    employeeList.setAdapter(adapter);

                                        }

}

The issue is after clearing the word from the edittext. it should go back to previous listview i.e, it should show all values in the db.

enter image description here

  • 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-03T09:21:26+00:00Added an answer on June 3, 2026 at 9:21 am

    Instead of using a second cursor, you should use a FilterQueryProvider with your EditText to update perform multiple updates to the ListView much like an AutoCompleteTextView.

    Or you could add a TextWatcher and change the cursor back to your first one whenever the length is becomes zero.

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

Sidebar

Related Questions

Creating a class with variables like this works fine : class Example { public
If on run/debug configuration, if I specify a launch activity, then my app runs
Creating an iOS app in Flash Builder 4.5 which is a small Hello World
I'm creating a searchable version of my university's course listings, and am not sure
Creating a view with following code. - (void)loadView { paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
Creating a simple public/private keypair, such as through ssh-keygen does not create a file
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a google map with store locations within 50 miles of user entered address.
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a server-side socket will fail if I'm trying to use the same port

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.