可搜索的界面 - 应用程序关闭

时间:2011-05-09 19:54:46

标签: android

所以即时制作一个Android应用程序,一旦尝试进入我的上一个活动,我的应用程序崩溃了。请检查是否有遗漏的东西。

Search1.Java

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Search1 extends Activity {

    String searchtype="null";

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);


        Button ISBN = (Button) findViewById(R.id.ISBN);  

        ISBN.setOnClickListener(new View.OnClickListener() { 
             public void onClick(View view) {      
                    onSearchRequested();
                    searchtype="ISBN";
             }

        });


        Button Title = (Button) findViewById(R.id.Title);  
    Title.setOnClickListener(new View.OnClickListener() { 
             public void onClick(View view) {      
                    onSearchRequested();
                    searchtype="Title";
             }
    //various listeners follow
        });...

Searchresults.java

public class SearchResults extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(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);
}
}

最后是两个文件的清单

<activity android:name=".SearchResults" >
<intent-filter>
    <action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
           android:resource="@xml/searchable"/>
</activity>

<activity    android:name=".Search1"
             android:label="@string/app_name"
             android:screenOrientation="portrait"> 
             <meta-data android:name="android.app.default_searchable"
                        android:value=".SearchResults" /> 
</activity>

Searchresults活动仍然不完整(xml文件只包含textview)但我仍然不认为当我尝试输入活动时应用程序应该强制关闭。这段代码有问题吗?

1 个答案:

答案 0 :(得分:0)

我经常忘记在AndroidManifest.xml中输入我的活动,你检查过这是不是问题? =)