Search functionality for Android (PLS HELP!)

I came across this tutorial and it's a good one for creating the search feature for Android:
Good Tutorial

I have a few questions I hope someone can help answer:

1.

First questionIt's saying this should be in it's own separate xml file. I already have a main xml which has the layout for the launcher, so do I just plug this on the main.xml file instead of creating a separate xml file? I want the search to be on the main launcher page.
<searchable
      xmlns:android="http://schemas.android.com/apk/res/android"
   android:label="@string/search_label"
   android:hint="@string/search_hint">
</searchable>

Open in new window

2.

Second question Then we are to add a new class file called SampleSearchActivity. Since I already have a Main.java file, what part of this code could I strip out to plug into my main.java file?
public class SampleSearchActivity extends ListActivity {
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      handleIntent(getIntent());
   } 

   public void onNewIntent(Intent intent) {
      setIntent(intent);
      handleIntent(intent);
   } 

   public void onListItemClick(ListView l,
      View v, int position, long id) {
      // call detail activity for clicked entry
   } 

   private void handleIntent(Intent intent) {
      if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
         String query =
               intent.getStringExtra(SearchManager.QUERY);
         doSearch(query);
      }
   }    

   private void doSearch(String queryStr) {
   // get a Cursor, prepare the ListAdapter
   // and set it
   }
}

Open in new window


3.

Final question This is the code that is then added to the manifest file...well, I'm confused here on how to integrate this file with my existing file.      
<application
   android:icon="@drawable/icon"
   android:label="@string/app_name"
   android:name=".YourApp" >
   <meta-data
      android:name="android.app.default_searchable"
      android:value=".SampleSearchActivity" />
   <activity
      android:label="@string/app_name"
      android:launchMode="singleTop"
      android:name=".SampleSearchActivity" >
      <intent-filter >
         <action android:name="android.intent.action.SEARCH" />
      </intent-filter>
      <intent-filter >
         <action android:name="android.intent.action.VIEW" />
      </intent-filter>
      <meta-data
         android:name="android.app.searchable"
         android:resource="@xml/searchable" />
   </activity>
</application>

Open in new window


Here's my manifest file:
  <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Test"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


        </activity>
    </application> 

Open in new window

teknovationAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KRUNAL TAILORFreelance Mobile DeveloperCommented:
Hi teknovation,

1)

Main.xml is the your launcher file, and the second one is Searchable.xml file. Add the following searchable.xml file in folder “res/xml”. This searchable xml is used in your manifest file.

<searchable
      xmlns:android="http://schemas.android.com/apk/res/android"
   android:label="@string/search_label"
   android:hint="@string/search_hint">
</searchable>

Open in new window


2) Main.java is your launcher file code. With SampleSearchActivity.java you can display the search list in tableview list. So, make it two separate files.

3) Make your manifest file
<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Test"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


        </activity>
        <activity
      android:label="@string/app_name"
      android:launchMode="singleTop"
      android:name=".SampleSearchActivity" >
      <intent-filter >
         <action android:name="android.intent.action.SEARCH" />
      </intent-filter>
      <intent-filter >
         <action android:name="android.intent.action.VIEW" />
      </intent-filter>
      <meta-data
         android:name="android.app.searchable"
         android:resource="@xml/searchable" />
   </activity>
    </application> 

Open in new window


Here is one more tutorial for you to refrence: http://javapapers.com/android/android-searchview-action-bar-tutorial/

Thanks & Regards,
Krunal T. Tailor

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
teknovationAuthor Commented:
I tried to create the same solution, but when I hit enter on the search, nothing happens. What could be the issue?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Android

From novice to tech pro — start learning today.