Search in sources :

Example 1 with SearchView

use of android.widget.SearchView in project k-9 by k9mail.

the class ChooseFolder method configureFolderSearchView.

private void configureFolderSearchView(Menu menu) {
    final MenuItem folderMenuItem = menu.findItem(R.id.filter_folders);
    final SearchView folderSearchView = (SearchView) folderMenuItem.getActionView();
    folderSearchView.setQueryHint(getString(R.string.folder_list_filter_hint));
    folderSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            folderMenuItem.collapseActionView();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mAdapter.getFilter().filter(newText);
            return true;
        }
    });
}
Also used : SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem)

Example 2 with SearchView

use of android.widget.SearchView in project plaid by nickbutcher.

the class SearchActivity method setNoResultsVisibility.

void setNoResultsVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noResults == null) {
            noResults = (TextView) ((ViewStub) findViewById(R.id.stub_no_search_results)).inflate();
            noResults.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchView.setQuery("", false);
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });
        }
        String message = String.format(getString(R.string.no_search_results), searchView.getQuery().toString());
        SpannableStringBuilder ssb = new SpannableStringBuilder(message);
        ssb.setSpan(new StyleSpan(Typeface.ITALIC), message.indexOf('“') + 1, message.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        noResults.setText(ssb);
    }
    if (noResults != null) {
        noResults.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) StyleSpan(android.text.style.StyleSpan) BindView(butterknife.BindView) View(android.view.View) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CheckedTextView(android.widget.CheckedTextView) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 3 with SearchView

use of android.widget.SearchView in project YourEyes by SevenLJY.

the class PoiSearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_poisearch);
    sv_destination = (SearchView) findViewById(R.id.sv_destination);
    lv_result = (ListView) findViewById(R.id.lv_result);
    poiItems = new ArrayList<PoiItem>();
    listItems = new ArrayList<Map<String, String>>();
    //对搜索框的设置
    //设置不自动缩小为图标
    sv_destination.setIconifiedByDefault(false);
    //显示搜索按钮
    sv_destination.setSubmitButtonEnabled(true);
    longitude = 0;
    latitude = 0;
    latitudeStatus = 0;
    city = "";
    //初始化定位
    initLocation();
    startLocation();
    //搜索框搜索监听
    sv_destination.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            //点击搜索时触发,将搜索结果展示在ListView中
            for (int num = 0; num < listItems.size(); num++) {
                listItems.get(num).clear();
            }
            listItems.clear();
            if (city.length() != 0) {
                //city值仍为""时无意义,搜索所得位置不在本城市,该处处理为不予显示
                query = new PoiSearch.Query(s, "", city);
                //设置每页展示20个结果
                query.setPageSize(10);
                //设置查询页码
                query.setPageNum(0);
                poiSearch = new PoiSearch(PoiSearchActivity.this, query);
                //设置周边搜索的中心点以及半径,以定位的当前位置为中心点
                poiSearch.setBound(new PoiSearch.SearchBound(new LatLonPoint(latitude, longitude), 3000));
                poiSearch.setOnPoiSearchListener(new PoiSearch.OnPoiSearchListener() {

                    @Override
                    public void onPoiSearched(PoiResult poiResult, int i) {
                        //搜索结果在列表中显示
                        if (i == 1000 && poiResult != null) {
                            poiItems = poiResult.getPois();
                            for (PoiItem item : poiItems) {
                                listItem = new HashMap<String, String>();
                                listItem.put("title", item.toString());
                                listItem.put("content", item.getCityName() + item.getAdName() + item.getSnippet());
                                listItem.put("latitude", Double.toString(item.getLatLonPoint().getLatitude()));
                                listItem.put("longitude", Double.toString(item.getLatLonPoint().getLongitude()));
                                listItems.add(listItem);
                                item.toString();
                            }
                            adapter = new SimpleAdapter(PoiSearchActivity.this, listItems, R.layout.array_poiitems, new String[] { "title", "content" }, new int[] { R.id.tv_title, R.id.tv_content });
                            lv_result.setAdapter(adapter);
                        } else {
                            ToastUtil.show(PoiSearchActivity.this, "无搜索结果 请检查关键字");
                        }
                    }

                    @Override
                    public void onPoiItemSearched(PoiItem poiItem, int i) {
                    //搜索结果回调,暂时不需使用
                    }
                });
                poiSearch.searchPOIAsyn();
            } else {
                ToastUtil.show(PoiSearchActivity.this, "正在获取定位信息  请稍候");
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            //搜索框文字改变时触发,暂不做优化
            return false;
        }
    });
    /**
         * 为列表项单击事件添加监听
         * 单击相应列表项时跳转到导航界面并将目的地传至导航界面
         * */
    lv_result.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Bundle data = new Bundle();
            data.putDouble("latitude", Double.parseDouble(listItems.get(i).get("latitude")));
            data.putDouble("longitude", Double.parseDouble(listItems.get(i).get("longitude")));
            data.putDouble("myLatitude", latitude);
            data.putDouble("myLongitude", longitude);
            if (latitude == 0) {
                ToastUtil.show(PoiSearchActivity.this, "您的定位信息出错,请检查是否打开了GPS");
            } else {
                Intent intent = new Intent(PoiSearchActivity.this, BasicWalkNaviActivity.class);
                intent.putExtras(data);
                startActivity(intent);
            }
        }
    });
}
Also used : PoiResult(com.amap.api.services.poisearch.PoiResult) PoiItem(com.amap.api.services.core.PoiItem) LatLonPoint(com.amap.api.services.core.LatLonPoint) PoiSearch(com.amap.api.services.poisearch.PoiSearch) Bundle(android.os.Bundle) SimpleAdapter(android.widget.SimpleAdapter) Intent(android.content.Intent) SearchView(android.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) LatLonPoint(com.amap.api.services.core.LatLonPoint) SearchView(android.widget.SearchView) AdapterView(android.widget.AdapterView) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with SearchView

use of android.widget.SearchView in project android_frameworks_base by ResurrectionRemix.

the class SelectPrinterActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.select_printer_activity, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String searchString) {
            ((DestinationAdapter) mListView.getAdapter()).getFilter().filter(searchString);
            return true;
        }
    });
    searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {

        @Override
        public void onViewAttachedToWindow(View view) {
            if (AccessibilityManager.getInstance(SelectPrinterActivity.this).isEnabled()) {
                view.announceForAccessibility(getString(R.string.print_search_box_shown_utterance));
            }
        }

        @Override
        public void onViewDetachedFromWindow(View view) {
            if (!isFinishing() && AccessibilityManager.getInstance(SelectPrinterActivity.this).isEnabled()) {
                view.announceForAccessibility(getString(R.string.print_search_box_hidden_utterance));
            }
        }
    });
    return true;
}
Also used : SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 5 with SearchView

use of android.widget.SearchView in project platform_frameworks_base by android.

the class SelectPrinterActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.select_printer_activity, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String searchString) {
            ((DestinationAdapter) mListView.getAdapter()).getFilter().filter(searchString);
            return true;
        }
    });
    searchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {

        @Override
        public void onViewAttachedToWindow(View view) {
            if (AccessibilityManager.getInstance(SelectPrinterActivity.this).isEnabled()) {
                view.announceForAccessibility(getString(R.string.print_search_box_shown_utterance));
            }
        }

        @Override
        public void onViewDetachedFromWindow(View view) {
            if (!isFinishing() && AccessibilityManager.getInstance(SelectPrinterActivity.this).isEnabled()) {
                view.announceForAccessibility(getString(R.string.print_search_box_hidden_utterance));
            }
        }
    });
    return true;
}
Also used : SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Aggregations

SearchView (android.widget.SearchView)66 View (android.view.View)34 TextView (android.widget.TextView)29 MenuItem (android.view.MenuItem)25 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)15 AdapterView (android.widget.AdapterView)14 RecyclerView (android.support.v7.widget.RecyclerView)12 SearchManager (android.app.SearchManager)11 Activity (android.app.Activity)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 SettingsActivity (com.android.settings.SettingsActivity)7 ViewGroup (android.view.ViewGroup)6 Toolbar (android.widget.Toolbar)6 Intent (android.content.Intent)4 MenuInflater (android.view.MenuInflater)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Nullable (android.support.annotation.Nullable)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)3