In my application, there are five activities containing very long text. I want to add find facility to my activity, so that when a user types something to the search bar then if the activity contains that word then the word should scroll to top automatically being highlighted.I am able to call the Search Dialog (as instructed in the Android Developer page). Can you guys help me compare the input in the search dialog with the texts in my activity and scroll it to top?
MainActivity.java
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.search:
onSearchRequested(); //opens the search dialog
break;
return super.onOptionsItemSelected(item);
}
SearchableActivity.java
public class SearchableActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
//Get the intent, verify the action and get the query
Intent intent = getIntent();
if (intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
private void doMySearch(String query) {
//what to do here???
}
}
Here the searchable activity is a different activity. How do I compare the search input with a text which is in another activity (MainActivity.java)?