在片段中搜索地图

时间:2014-08-25 18:49:02

标签: android android-fragments

我正在更改我的应用程序以使用片段,并且我在片段中搜索我的地图标记时遇到问题。当它是一项活动时,我这样做了:

search.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

        boolean handled = false;
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            String searchText = search.getText().toString();

            // hide the virtual keyboard
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 
                                      InputMethodManager.RESULT_UNCHANGED_SHOWN);

            handled = true;

            boolean found = false;

            for(Marker m : list) {

                if(m.getTitle().contains(searchText)){
                    m.showInfoWindow();
                    found = true;
                    break;
                } else if(m.getSnippet().contains(searchText)) {
                    m.showInfoWindow();
                    found = true;
                    break;
                }
            }

            if(found == false) {
                Toast.makeText(getApplicationContext(), "No Matches Found", Toast.LENGTH_SHORT).show();
            }
        }

        return handled;
    }
});

当我在片段中使用它时,"发现"总是假的。我需要更改什么来使其在片段中工作?

1 个答案:

答案 0 :(得分:0)

嗯,我觉得愚蠢。我忘了将每个标记添加到我的数组中。