I have successfully gotten my action bar to show up right in android. I am now trying to implement the search. I am trying to start small and at least see if I can get the search term before I try and do anything with it.
I followed this tutorial here:
http://developer.android.com/training/search/setup.html
and created a SearchResultsActivity class which looks like this to handle the search.
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class SearchResultsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
//possible more code
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
//possible more code
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
//use the query to search your data somehow
//toast error test
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, query, duration);
toast.show();
}
}
///more code
}
I tried to add a toast to see if when I entered text then clicked search if a toast would pop up. Right now no toast shows up.