I'm new to android development.
I have an activity containing a bunch of fragments, each fragment shows a different text. I set the text at runtime from strings.xml (i.e tv.setText...)
Here is an example of my strings.xml:
<string name="string1">the content I want searched, text1</string>
<string name="string2">the content I want searched, text2</string>
<string name="string3">the content I want searched, text3</string>
This is my problem:
I want to add search functionality in the app, I want to be able to search for words inside the strings and return the whole string to the user as a result.
So for example if the user searches for text2, It would return the whole string.
I already read the search guide on android-developers here: http://developer.android.com/guide/topics/search/index.html
I also found a bunch of tutorials, but all of them seem to deal with data stored in SQLite databases.
Here is more of my code:
searchable.xml:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="Search" >
</searchable>
SearchableActivity:
public class SearchableActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
private void doMySearch(String query) {
}
}
Any help would be appreciated
P.S Is this the best way to do this? I have a lot of strings (>1000) I read about using databases instead but I don't know how to convert all my data into a db, and don't know how to set text from a db...etc