我想在点击按钮时启动搜索活动,现在没有调用oncreate()
。我怀疑AndroidManifest.xml
中有错误,但无法找到它..
Main_Activity
public void search(View view) {
Log.d("search", "start searchButton"); //this is shown in logcat
onSearchRequested();
}
的AndroidManifest.xml
<!--Main activity.-->
<activity
android:name=".Main_Activity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".Search_Activity" />
</activity>
<!--Activity and metadata for search activity. -->
<activity
android:name=".Search_Activity"
android:label="@string/app_name"
android:launchMode="singleTop" >
<intent-filter >
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
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="@string/search_hint"
</searchable>
search_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/searchList" />
</LinearLayout>
Search_Activity.java
public class Search_Activity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d("search", "start search"); //does not show in logcat!!!!!!!!!!
super.onCreate(savedInstanceState);
setContentView(R.layout.search_layout);
handleIntent(getIntent());
}
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
public void onListItemClick(ListView l,
View v, int position, long id) {
// call detail activity for clicked entry
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query =
intent.getStringExtra(SearchManager.QUERY);
doSearch(query);
}
}
private void doSearch(String queryStr) {
// get a Cursor, prepare the ListAdapter
// and set it
}
}
有人看到了错误吗?或者我怎么能找出问题的想法?
答案 0 :(得分:0)
您应该使用Intent
开始一项新活动。试试这个:
public void search(View view) {
Log.d("search", "start searchButton"); //this is shown in logcat
startActivity(new Intent(this, Search_Activity.class));
}