@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_poisearch); lif = LayoutInflater.from(this); // 初始化搜索模块,注册搜索事件监听 mPoiSearch = PoiSearch.newInstance(); mPoiSearch.setOnGetPoiSearchResultListener(this); mSuggestionSearch = SuggestionSearch.newInstance(); mSuggestionSearch.setOnGetSuggestionResultListener(this); keyWorldsView = (AutoCompleteTextView) findViewById(R.id.searchkey); sugAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line); keyWorldsView.setAdapter(sugAdapter); mBaiduMap = ((SupportMapFragment) (getSupportFragmentManager().findFragmentById(R.id.map))) .getBaiduMap(); poi_lv = (ListView) findViewById(R.id.poi_lv); poiResultAdapter = new PoiResultAdapter(); poiResultAdapter2 = new PoiResultAdapter2(); poi_lv.setAdapter(poiResultAdapter); poi_lv.setOnItemClickListener(this); /** 当输入关键字变化时,动态更新建议列表 */ keyWorldsView.addTextChangedListener( new TextWatcher() { @Override public void afterTextChanged(Editable arg0) {} @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {} @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { if (cs.length() <= 0) { return; } /** 使用建议搜索服务获取建议列表,结果在onSuggestionResult()中更新 */ mSuggestionSearch.requestSuggestion( (new SuggestionSearchOption()).keyword(cs.toString()).city(city)); } }); }
@Override protected void onDestroy() { mPoiSearch.destroy(); mSuggestionSearch.destroy(); super.onDestroy(); }