Android Open Source - hello-srch2-android-sdk Search Activity






From Project

Back to project page hello-srch2-android-sdk.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project hello-srch2-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.srch2.android.demo.sqlite;
/*w w  w.  j  av a  2  s .  c om*/
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

import com.srch2.android.sdk.SRCH2Engine;
import com.srch2.android.sdk.SearchResultsListener;


public class SearchActivity extends Activity implements InstantSearchEditText.SearchInputEnteredObserver {

    DatabaseHelper mDatabaseHelper;
    SQLiteBookIndex mDatabaseIndexable;

    private ListView mSearchResultsListView;
    private SearchResultsAdapter mSearchResultsAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        mSearchResultsListView = (ListView) findViewById(R.id.lv_search_results);
        mSearchResultsAdapter = new SearchResultsAdapter(this);
        mSearchResultsListView.setAdapter(mSearchResultsAdapter);
        mDatabaseHelper = new DatabaseHelper(this);
        mDatabaseIndexable = new SQLiteBookIndex(mDatabaseHelper);
    }

    @Override
    protected void onResume() {
        super.onResume();
        SRCH2Engine.setSQLiteIndexables(mDatabaseIndexable);
        SRCH2Engine.onResume(this, (SearchResultsListener) mSearchResultsAdapter, true);
    }

    @Override
    protected  void onPause() {
        super.onPause();
        SRCH2Engine.onPause(this);
    }

    @Override
    public void onNewSearchInput(String newSearchText) {
        // Pass the text of the InstantSearchEditText input field to the SRCH2Engine for doing
        // searches. A search could also be performed here specifically on mMovieIndex by calling
        // either mMovieIndex.search(newSearchText) or SRCH2Engine.searchIndex(MovieIndex.INDEX_NAME).
        SRCH2Engine.searchAllIndexes(newSearchText);
    }

    @Override
    public void onNewSearchInputIsBlank() {
        // Since the input field of the InstantSearchEditText is now empty, notify the
        // SRCH2Engine the search input is empty and clear the results of the list view by clearing
        // the data set of its backing adapter.
        SRCH2Engine.searchAllIndexes("");
        mSearchResultsAdapter.clearDisplayedSearchResults();
    }
}




Java Source Code List

com.srch2.android.demo.helloworld.ApplicationTest.java
com.srch2.android.demo.helloworld.InstantSearchEditText.java
com.srch2.android.demo.helloworld.MovieIndex.java
com.srch2.android.demo.helloworld.MovieSearchResult.java
com.srch2.android.demo.helloworld.SearchActivity.java
com.srch2.android.demo.helloworld.SearchResultsAdapter.java
com.srch2.android.demo.sqlite.ApplicationTest.java
com.srch2.android.demo.sqlite.BookSearchResult.java
com.srch2.android.demo.sqlite.Book.java
com.srch2.android.demo.sqlite.DatabaseHelper.java
com.srch2.android.demo.sqlite.InstantSearchEditText.java
com.srch2.android.demo.sqlite.SQLiteBookIndex.java
com.srch2.android.demo.sqlite.SearchActivity.java
com.srch2.android.demo.sqlite.SearchResultsAdapter.java