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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:28:29+00:00 2026-06-13T14:28:29+00:00

The Search function in my Android app works. I’m using onSearchRequested() ; to invoke

  • 0

The Search function in my Android app works. I’m using onSearchRequested(); to invoke the Search function. Now what I’d like to do is not use onSearchRequested(); and pass a string from an EditText to the search method and display the results in a List. Here’s my search as it’s working when onSearchRequested is called:

SearchPage Activity:

    DBHelper = new DBAdapter(this);
    DBHelper.open();
    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        showResults(query);

    }
    //--- END onSearchRequested


private void showResults(String query) {
    Cursor cursor = DBHelper.searchDB(query);
    startManagingCursor(cursor);
    String[] searchFrom = new String[] { DBAdapter.KEY_YEAR,
            DBAdapter.KEY_MAKE, DBAdapter.KEY_MODEL };
    int[] displayHere = new int[] { R.id.rYearTV, R.id.rMakeTV,
            R.id.rModelTV };

    final SimpleCursorAdapter records = new SimpleCursorAdapter(this,
            R.layout.record_2, cursor, searchFrom, displayHere);

    setListAdapter(records);

DBAdapter Activity:

//--- GET RECORDS FOR SEARCH
    public Cursor searchDB(String query) { 

    String[] parts = query.split(" "); 

    String queryString = ""; 
    for(int i = 0; i < parts.length; i++) { 
        queryString += KEY_YEAR + " LIKE '%" + parts[i] + "%' OR "; 
        queryString += KEY_MAKE + " LIKE '%" + parts[i] + "%' OR "; 
        queryString += KEY_MODEL + " LIKE '%" + parts[i] + "%'"; 
        if(i != (parts.length - 1)) { 
            queryString += " OR "; 
        } 
    } 

    return db.query(true, DB_TABLE,  
        new String[] { KEY_ROWID, KEY_SDATE, KEY_YEAR, KEY_MAKE, KEY_MODEL },  
        queryString, null, null, null, null, null); 
}
//--- END Get Records for Search

I’d like to pass a String into the search function String searchData = searchEditText.getText().toString(); and have the search function go to work on the passed string by pressing a “Search” button. Can someone help get me started?

  • 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-13T14:28:30+00:00Added an answer on June 13, 2026 at 2:28 pm

    You should have EditText like that in your layout:

           <EditText
                android:id="@+id/search_query"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="search"
                android:imeOptions="actionSearch"
                android:inputType="text" />
    

    And in your Activity’s onCreate:

    EditText searchQuery = (EditText) findViewById(R.id.search_query);
    searchQuery.setOnEditorActionListener(new OnEditorActionListener() {
                public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                        String searchData = searchQuery.getText().toString();
                                showResults(searchData); //passing string to search in your database to your method
                        return true;
                    }
                    return false;
                }
        });
    

    setOnEditorActionListener is used to perform search when user presses search button on keayboard. You can read more about imeActions here.

    According to your code call showResults(searchData); to make search and display results in a list.


    EDIT:
    According to your code call it in SearchPage Activity:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        //setContentView and other your features
    
        DBHelper = new DBAdapter(this);
        DBHelper.open();
    
        EditText searchQuery = (EditText) findViewById(R.id.search_query);
    
        Button yourButton = (Button) findViewById(R.id.yourButtonId);
        yourButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                String searchData = searchQuery.getText().toString();
                showResults(searchQuery);
            }
        });
    }
    
    private void showResults(String query) {
        Cursor cursor = DBHelper.searchDB(query);
        startManagingCursor(cursor);
        String[] searchFrom = new String[] { DBAdapter.KEY_YEAR,
                DBAdapter.KEY_MAKE, DBAdapter.KEY_MODEL };
        int[] displayHere = new int[] { R.id.rYearTV, R.id.rMakeTV,
                R.id.rModelTV };
    
        final SimpleCursorAdapter records = new SimpleCursorAdapter(this,
                R.layout.record_2, cursor, searchFrom, displayHere);
    
        setListAdapter(records);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android app and I would like to implement the search function.
I would like to implement a search function in my android app. I sow
I am building a android-based app to implement twitter search function. The button click
I want to make a search function to my android app. I want the
I'm still trying to implement a search function into my Android app. So far
I have a search function in my project. In the searchable.xml, i would like
I have created a Google Search function, however I would like to leave the
I am using 'jquery-ui-map' for an android app. My emulator is Google API Level
Button Click of my Android App using Sencha Touch 2 is working fine in
I am currently trying to integrate a live search functionality in android. I use

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.