2011-10-13 124 views
1

現在我有這個搜索欄,下面的代碼。搜索欄,但無法搜索。

鏈接:http://pastebin.com/6vSBR8iX

我如何讓它成爲搜索窗口,如市場有類型?

這是我的Android清單。

鏈接:http://pastebin.com/ue6NSTCr

有人請幫我出這一點。我已經嘗試過

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

但是無法搜索到。

+0

任何人都可以建議如何解決像androidmarket的搜索欄? – FreshMeat

回答

0

你有沒有跟着蒞臨指導:http://developer.android.com/guide/topics/search/search-dialog.html#PerformingSearch

如果您已經創建活動和操作欄小工具,我希望你沒有忘記補充:

public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the options menu from XML 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.options_menu, menu); 

    // Get the SearchView and set the searchable configuration 
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); 
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default 
    return true; 
} 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case R.id.search: 
      onSearchRequested(); 
      return true; 
     default: 
      return false; 
    } 
} 

,並澄清你的問題,你能不能請發佈更多信息?

乾杯!