title: Creating a search tab which searches a text file in Android Studio
body: <p>Im trying to create an android app with two tabs. One tab will search for data then display it in a listview, when you select one item there it will redirect you to another tab showing the full item (more like a dictionary,showing a list of words and when you click a word it will show you the full meaning of a word in another tab). I'm having problems implementing the search part. I followed the steps on the official android site: <a href="http://developer.android.com/training/search/setup.html" rel="nofollow">http://developer.android.com/training/search/setup.html</a>.</p>
  
  <p>but Im getting errors when I try to change the Manifest file,here is my Manifest file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.swm.empire.psalmsongbook" &gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".SplashScreen"
              android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN"/&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER"/&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity
              android:name=".SearchResultsActivity"
              android:label="@string/app_name"&gt;
  
          &lt;action android:name="android.intent.action.SEARCH" /&gt;
          &lt;category android:name="android.intent.category.LAUNCHER"
  
  
          &lt;meta-data
              android:name="android.app.searchable"
              android:resource="@xml/searchable" /&gt;
  
              /&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>My Tab2.java is the one which handles the search page, here is my Tab2.java file:</p>
  
  <pre><code>package com.swm.empire.psalmsongbook;
  
  import android.app.SearchManager;
  import android.content.Context;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.SearchView;
  
  /**
   * Created by VinceGee on 7/22/2015.
  
  public class Tab2 extends Fragment {
  @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.tab_2, container, false);
      return v;
  }*/
  
  
  public class Tab2{
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.options_menu, menu);
  
      return true;
  }
  
  // Associate searchable configuration with the SearchView
  SearchManager searchManager = (SearchManager)    getSystemService(Context.SEARCH_SERVICE);
  
  SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  
  return true;
  }
  
  
  
  }
  </code></pre>
  
  <p>I created a DatabaseTable.java as the article said here it is:</p>
  
  <p><code>package com.swm.empire.psalmsongbook;</code></p>
  
  <pre><code>import android.app.SearchManager;
  import android.content.BroadcastReceiver;
  import android.content.ComponentName;
  import android.content.ContentResolver;
  import android.content.ContentValues;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.content.IntentSender;
  import android.content.ServiceConnection;
  import android.content.SharedPreferences;
  import android.content.pm.ApplicationInfo;
  import android.content.pm.PackageManager;
  import android.content.res.AssetManager;
  import android.content.res.Configuration;
  import android.content.res.Resources;
  import android.database.Cursor;
  import android.database.DatabaseErrorHandler;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  import android.database.sqlite.SQLiteQueryBuilder;
  import android.graphics.Bitmap;
  import android.graphics.drawable.Drawable;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Looper;
  import android.os.UserHandle;
  import android.support.annotation.Nullable;
  import android.text.TextUtils;
  import android.util.Log;
  import android.view.Display;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  
  /**
   * Created by VinceGee on 7/23/2015.
   */
  
  public class DatabaseTable extends Context {
      private static final String TAG = "DictionaryDatabase";
  
  //The columns we'll include in the dictionary table
  public static final String COL_WORD = "SONG";
  public static final String COL_DEFINITION = "LYRIC";
  
  private static final String DATABASE_NAME = "SONGBOOK";
  private static final String FTS_VIRTUAL_TABLE = "FTS";
  private static final int DATABASE_VERSION = 1;
  
  private final DatabaseOpenHelper mDatabaseOpenHelper;
  
  public DatabaseTable(Context context) {
      mDatabaseOpenHelper = new DatabaseOpenHelper(context);
  }
  
  @Override
  public AssetManager getAssets() {
      return null;
  }
  
  @Override
  public Resources getResources() {
      return null;
  }
  
  @Override
  public PackageManager getPackageManager() {
      return null;
  }
  
  @Override
  public ContentResolver getContentResolver() {
      return null;
  }
  
  @Override
  public Looper getMainLooper() {
      return null;
  }
  
  @Override
  public Context getApplicationContext() {
      return null;
  }
  
  @Override
  public void setTheme(int resid) {
  
  }
  
  @Override
  public Resources.Theme getTheme() {
      return null;
  }
  
  @Override
  public ClassLoader getClassLoader() {
      return null;
  }
  
  @Override
  public String getPackageName() {
      return null;
  }
  
  @Override
  public ApplicationInfo getApplicationInfo() {
      return null;
  }
  
  @Override
  public String getPackageResourcePath() {
      return null;
  }
  
  @Override
  public String getPackageCodePath() {
      return null;
  }
  
  @Override
  public SharedPreferences getSharedPreferences(String name, int mode) {
      return null;
  }
  
  @Override
  public FileInputStream openFileInput(String name) throws FileNotFoundException {
      return null;
  }
  
  @Override
  public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException {
      return null;
  }
  
  @Override
  public boolean deleteFile(String name) {
      return false;
  }
  
  @Override
  public File getFileStreamPath(String name) {
      return null;
  }
  
  @Override
  public File getFilesDir() {
      return null;
  }
  
  @Override
  public File getNoBackupFilesDir() {
      return null;
  }
  
  @Nullable
  @Override
  public File getExternalFilesDir(String type) {
      return null;
  }
  
  @Override
  public File[] getExternalFilesDirs(String type) {
      return new File[0];
  }
  
  @Override
  public File getObbDir() {
      return null;
  }
  
  @Override
  public File[] getObbDirs() {
      return new File[0];
  }
  
  @Override
  public File getCacheDir() {
      return null;
  }
  
  @Override
  public File getCodeCacheDir() {
      return null;
  }
  
  @Nullable
  @Override
  public File getExternalCacheDir() {
      return null;
  }
  
  @Override
  public File[] getExternalCacheDirs() {
      return new File[0];
  }
  
  @Override
  public File[] getExternalMediaDirs() {
      return new File[0];
  }
  
  @Override
  public String[] fileList() {
      return new String[0];
  }
  
  @Override
  public File getDir(String name, int mode) {
      return null;
  }
  
  @Override
  public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
      return null;
  }
  
  @Override
  public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
      return null;
  }
  
  @Override
  public boolean deleteDatabase(String name) {
      return false;
  }
  
  @Override
  public File getDatabasePath(String name) {
      return null;
  }
  
  @Override
  public String[] databaseList() {
      return new String[0];
  }
  
  @Override
  public Drawable getWallpaper() {
      return null;
  }
  
  @Override
  public Drawable peekWallpaper() {
      return null;
  }
  
  @Override
  public int getWallpaperDesiredMinimumWidth() {
      return 0;
  }
  
  @Override
  public int getWallpaperDesiredMinimumHeight() {
      return 0;
  }
  
  @Override
  public void setWallpaper(Bitmap bitmap) throws IOException {
  
  }
  
  @Override
  public void setWallpaper(InputStream data) throws IOException {
  
  }
  
  @Override
  public void clearWallpaper() throws IOException {
  
  }
  
  @Override
  public void startActivity(Intent intent) {
  
  }
  
  @Override
  public void startActivity(Intent intent, Bundle options) {
  
  }
  
  @Override
  public void startActivities(Intent[] intents) {
  
  }
  
  @Override
  public void startActivities(Intent[] intents, Bundle options) {
  
  }
  
  @Override
  public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException {
  
  }
  
  @Override
  public void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException {
  
  }
  
  @Override
  public void sendBroadcast(Intent intent) {
  
  }
  
  @Override
  public void sendBroadcast(Intent intent, String receiverPermission) {
  
  }
  
  @Override
  public void sendOrderedBroadcast(Intent intent, String receiverPermission) {
  
  }
  
  @Override
  public void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
  
  }
  
  @Override
  public void sendBroadcastAsUser(Intent intent, UserHandle user) {
  
  }
  
  @Override
  public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission) {
  
  }
  
  @Override
  public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
  
  }
  
  @Override
  public void sendStickyBroadcast(Intent intent) {
  
  }
  
  @Override
  public void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
  
  }
  
  @Override
  public void removeStickyBroadcast(Intent intent) {
  
  }
  
  @Override
  public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) {
  
  }
  
  @Override
  public void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
  
  }
  
  @Override
  public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) {
  
  }
  
  @Nullable
  @Override
  public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
      return null;
  }
  
  @Nullable
  @Override
  public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) {
      return null;
  }
  
  @Override
  public void unregisterReceiver(BroadcastReceiver receiver) {
  
  }
  
  @Nullable
  @Override
  public ComponentName startService(Intent service) {
      return null;
  }
  
  @Override
  public boolean stopService(Intent service) {
      return false;
  }
  
  @Override
  public boolean bindService(Intent service, ServiceConnection conn, int flags) {
      return false;
  }
  
  @Override
  public void unbindService(ServiceConnection conn) {
  
  }
  
  @Override
  public boolean startInstrumentation(ComponentName className, String profileFile, Bundle arguments) {
      return false;
  }
  
  @Override
  public Object getSystemService(String name) {
      return null;
  }
  
  @Override
  public int checkPermission(String permission, int pid, int uid) {
      return 0;
  }
  
  @Override
  public int checkCallingPermission(String permission) {
      return 0;
  }
  
  @Override
  public int checkCallingOrSelfPermission(String permission) {
      return 0;
  }
  
  @Override
  public void enforcePermission(String permission, int pid, int uid, String message) {
  
  }
  
  @Override
  public void enforceCallingPermission(String permission, String message) {
  
  }
  
  @Override
  public void enforceCallingOrSelfPermission(String permission, String message) {
  
  }
  
  @Override
  public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
  
  }
  
  @Override
  public void revokeUriPermission(Uri uri, int modeFlags) {
  
  }
  
  @Override
  public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
      return 0;
  }
  
  @Override
  public int checkCallingUriPermission(Uri uri, int modeFlags) {
      return 0;
  }
  
  @Override
  public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) {
      return 0;
  }
  
  @Override
  public int checkUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags) {
      return 0;
  }
  
  @Override
  public void enforceUriPermission(Uri uri, int pid, int uid, int modeFlags, String message) {
  
  }
  
  @Override
  public void enforceCallingUriPermission(Uri uri, int modeFlags, String message) {
  
  }
  
  @Override
  public void enforceCallingOrSelfUriPermission(Uri uri, int modeFlags, String message) {
  
  }
  
  @Override
  public void enforceUriPermission(Uri uri, String readPermission, String writePermission, int pid, int uid, int modeFlags, String message) {
  
  }
  
  @Override
  public Context createPackageContext(String packageName, int flags) throws PackageManager.NameNotFoundException {
      return null;
  }
  
  @Override
  public Context createConfigurationContext(Configuration overrideConfiguration) {
      return null;
  }
  
  @Override
  public Context createDisplayContext(Display display) {
      return null;
  }
  
  private static class DatabaseOpenHelper extends SQLiteOpenHelper {
  
      private final Context mHelperContext;
      private SQLiteDatabase mDatabase;
  
      private static final String FTS_TABLE_CREATE =
              "CREATE VIRTUAL TABLE " + FTS_VIRTUAL_TABLE +
                      " USING fts3 (" +
                      COL_WORD + ", " +
                      COL_DEFINITION + ")";
  
      DatabaseOpenHelper(Context context) {
          super(context, DATABASE_NAME, null, DATABASE_VERSION);
          mHelperContext = context;
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          mDatabase = db;
          mDatabase.execSQL(FTS_TABLE_CREATE);
          loadSongbook();
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                  + newVersion + ", which will destroy all old data");
          db.execSQL("DROP TABLE IF EXISTS " + FTS_VIRTUAL_TABLE);
          onCreate(db);
      }
  
      private void loadSongbook() {
          new Thread(new Runnable() {
              public void run() {
                  try {
                      loadWords();
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              }
          }).start();
      }
  
      private void loadWords() throws IOException {
          final Resources resources = mHelperContext.getResources();
          InputStream inputStream = resources.openRawResource(R.raw.songs);
          BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
  
          try {
              String line;
              while ((line = reader.readLine()) != null) {
                  String[] strings = TextUtils.split(line, "-");
                  if (strings.length &lt; 2) continue;
                  long id = addWord(strings[0].trim(), strings[1].trim());
                  if (id &lt; 0) {
                      Log.e(TAG, "unable to add word: " + strings[0].trim());
                  }
              }
          } finally {
              reader.close();
          }
      }
  
      public long addWord(String song, String lyric) {
          ContentValues initialValues = new ContentValues();
          initialValues.put(COL_WORD, song);
          initialValues.put(COL_DEFINITION, lyric);
  
          return mDatabase.insert(FTS_VIRTUAL_TABLE, null, initialValues);
      }
  }
  public Cursor getWordMatches(String query, String[] columns) {
      String selection = COL_WORD + " MATCH ?";
      String[] selectionArgs = new String[] {query+"*"};
  
      return query(selection, selectionArgs, columns);
  }
  
  private Cursor query(String selection, String[] selectionArgs, String[] columns) {
      SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
      builder.setTables(FTS_VIRTUAL_TABLE);
  
      Cursor cursor = builder.query(mDatabaseOpenHelper.getReadableDatabase(),
              columns, selection, selectionArgs, null, null, null);
  
      if (cursor == null) {
          return null;
      } else if (!cursor.moveToFirst()) {
          cursor.close();
          return null;
      }
      return cursor;
  }
  
  DatabaseTable db = new DatabaseTable(this);
  
  private void handleIntent(Intent intent) {
  
      if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
          String query = intent.getStringExtra(SearchManager.QUERY);
          Cursor c = db.getWordMatches(query, null);
          //process Cursor and display results
      }
  }
  }
  </code></pre>
  
  <p>There is bunch of code Android studio added to fix this portion: </p>
  
  <pre><code>DatabaseTable db = new DatabaseTable(this);
  
  private void handleIntent(Intent intent) {
  
      if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
          String query = intent.getStringExtra(SearchManager.QUERY);
          Cursor c = db.getWordMatches(query, null);
          //process Cursor and display results
      }
  }
  }
  </code></pre>
  
  <p>So please correct me where I'm going wrong, or give a better method, I have searched around but other methods that i found provide searching from code output and not from a text file.</p>