0

我尝试遵循开发人员指南并检查了与此类似的错误,我的清单和可搜索文件看起来不错,但仍然没有出现搜索对话框。提前感谢任何帮助。

ser.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/hint">
</searchable>

清单.xml

<activity
            android:name="e.ftsexample.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/ser" />
        </activity>

主要活动

public class MainActivity extends Activity {
    DbS cr;
    private String[] from;
    private int[] to;
    private SimpleCursorAdapter str;
    private ListView LS;
    SQLiteDatabase ss;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cr = new DbS(getApplicationContext());
        setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
        GetMysearch(getIntent());
        // views
        LS = (ListView) findViewById(R.id.listView1);
        from = new String[] { DbS.Name_Col, DbS.Number_col };
        to = new int[] { R.id.sV, R.id.sVS };
        ss = cr.getWritableDatabase();
        Cursor currr = ss.query(DbS.Table_Name, new String[] { " rowid _id ",
                DbS.Name_Col, DbS.Number_col }, null, null, null, null, null);

        str = new SimpleCursorAdapter(this, R.layout.qss, currr, from, to, 0);

        LS.setAdapter(str);
    }

    private void GetMysearch(Intent myint) {
        // TODO Auto-generated method stub
        // Intent myint = getIntent();
        if (Intent.ACTION_SEARCH.equals(myint.getAction())) {
            String query = myint.getStringExtra(SearchManager.QUERY);
            Log.e("Reached", "intent");
            doMySearch(query);
        }
    }

    private void doMySearch(String query) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "QUERY REACHED",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onSearchRequested() {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "onSearchRequested",
                Toast.LENGTH_SHORT).show();
        return super.onSearchRequested();

    }


    @Override
    protected void onNewIntent(Intent intent) {
        Toast.makeText(getApplicationContext(), "Intet passed",
                Toast.LENGTH_SHORT).show();
        setIntent(intent);
        GetMysearch(intent);
    }
}
4

1 回答 1

1

尝试将此添加到您的活动中:

<meta-data
android:name="android.app.default_searchable"
android:value="e.ftsexample.MainActivity" />

编辑:原因是您将活动配置为接收搜索查询,而不是启动搜索。您可以将其添加到任何其他活动并通过调用开始搜索 onSearchRequested();

希望这有帮助。

于 2013-06-15T16:14:09.997 回答