【发布时间】:2013-05-30 23:28:07
【问题描述】:
我已成功让我的操作栏显示在 android 中。我现在正在尝试实现搜索。我正在尝试从小处着手,至少在尝试对搜索词进行任何操作之前先看看我是否可以获得搜索词。
我在这里学习了这个教程:
http://developer.android.com/training/search/setup.html
并创建了一个看起来像这样的 SearchResultsActivity 类来处理搜索。
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
}
我尝试添加 toast 以查看当我输入文本然后单击搜索时是否会弹出 toast。现在没有吐司出现。
【问题讨论】:
标签: android toast android-search