搜索对话框不显示

时间:2013-06-15 16:06:59

标签: android

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

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>

的manifest.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>

Mainactivity

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);
    }
}

1 个答案:

答案 0 :(得分:1)

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

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

修改:原因是您将活动配置为接收搜索查询,但未启动搜索。您可以将此活动添加到任何其他活动,并通过callin onSearchRequested();开始搜索

希望这有帮助。