2014-12-02 33 views
0

有人能幫助我建議如何設置一個特定的文本到搜索對話框嗎?我知道如何設置「提示」,我通過xml文件執行此操作。但我想根據上次搜索的內容將文本設置到搜索對話框。我打算通過SharedPreference檢索它。我只是不知道如何設置文本。如何設置搜索對話框的文本 - Android

感謝

回答

0

傳遞查詢字符串作爲額外的意圖在您的搜索活動,找回它,如下圖所示:

@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); 
     doMySearch(query); 
    } 
} 

參考 - http://developer.android.com/guide/topics/search/search-dialog.html#ReceivingTheQuery

+0

感謝您的答覆。我瞭解如何檢索搜索查詢,我的意思是如何在上次搜索的對話框中顯示搜索詞。例如,一個人輸入「託尼布萊爾」,按搜索,連接問題隨之而來,但他的搜索詞仍然存在,並在搜索對話框中可見。因此,他不必再次鍵入它......我只是不知道如何設置文本到搜索對話框。 – david 2014-12-03 08:35:11