每次item点击都会停止与你系那个
代码如下:
ublic class searchMode extends Activity implements OnPoiSearchListener{
private Button mbtn_ok,mbtn_back;//返回和搜索按钮
private ListView pListView;
private String city_curr,addr_curr;
private EditText edit_key;
private PoiSearch search;
private PoiSearch.Query query;//返回查询的类
private String keyword;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchmode);
init();
Onclick();
}
private void init() {
// TODO Auto-generated method stub
String Activityfrom= getIntent().getStringExtra("ActivityFrom");
if(Activityfrom!=null){
if(Activityfrom.equals("map_main")){ //跳转来自 main
city_curr= getIntent().getStringExtra("curr_city");
addr_curr= getIntent().getStringExtra("curr_addr");
}
}
mbtn_ok=(Button) findViewById(R.id.ss_search_start);
mbtn_back=(Button) findViewById(R.id.ss_search_back);
pListView=(ListView) findViewById(R.id.listViewResult);
edit_key=(EditText) findViewById(R.id.ss_search_edit);
}
private void Onclick() {
// TODO Auto-generated method stub
mbtn_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
keyword = edit_key.getText().toString();
if(keyword.equals("")){
Toast.makeText(searchMode.this,"请输入地址!", Toast.LENGTH_SHORT).show();
}
else{
search(keyword);
}
}
});
mbtn_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
pListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
PoiItem poi=(PoiItem)parent.getAdapter().getItem(position);//这里问题
double lon = poi.getLatLonPoint().getLongitude();
}
});
}
private void search(String keyword) {
// TODO Auto-generated method stub
query = new Query(keyword, null, city_curr); //搜索定位城市
query.setPageSize(10);
query.setPageNum(1);
//查询兴趣点
search = new PoiSearch(this, query);
search.setOnPoiSearchListener(this);
search.searchPOIAsyn();
}
@Override
public void onPoiItemDetailSearched(PoiItemDetail arg0, int arg1) {//setOnPoiSearchListener
// TODO Auto-generated method stub
System.out.println("onPoiItemDetailSearched调用了");
}
@Override
public void onPoiSearched(PoiResult poiResult, int rCode) {//setOnPoiSearchListener
// TODO Auto-generated method stub
System.out.println("onPoiSearched调用了"+poiResult+"------rCode"+rCode);
List<String> strs = new ArrayList<String>();
ArrayList<PoiItem> items = poiResult.getPois();
if (items != null && items.size() > 0) {
PoiItem item = null;
for (int i = 0, count = items.size(); i < count; i++) {
item = items.get(i);
strs.add(item.getTitle());
}
// 给ListView赋值,显示结果
ArrayAdapter<String> array = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strs);
pListView.setAdapter(array);
}
}
}
代码如下:
ublic class searchMode extends Activity implements OnPoiSearchListener{
private Button mbtn_ok,mbtn_back;//返回和搜索按钮
private ListView pListView;
private String city_curr,addr_curr;
private EditText edit_key;
private PoiSearch search;
private PoiSearch.Query query;//返回查询的类
private String keyword;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchmode);
init();
Onclick();
}
private void init() {
// TODO Auto-generated method stub
String Activityfrom= getIntent().getStringExtra("ActivityFrom");
if(Activityfrom!=null){
if(Activityfrom.equals("map_main")){ //跳转来自 main
city_curr= getIntent().getStringExtra("curr_city");
addr_curr= getIntent().getStringExtra("curr_addr");
}
}
mbtn_ok=(Button) findViewById(R.id.ss_search_start);
mbtn_back=(Button) findViewById(R.id.ss_search_back);
pListView=(ListView) findViewById(R.id.listViewResult);
edit_key=(EditText) findViewById(R.id.ss_search_edit);
}
private void Onclick() {
// TODO Auto-generated method stub
mbtn_ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
keyword = edit_key.getText().toString();
if(keyword.equals("")){
Toast.makeText(searchMode.this,"请输入地址!", Toast.LENGTH_SHORT).show();
}
else{
search(keyword);
}
}
});
mbtn_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
pListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
PoiItem poi=(PoiItem)parent.getAdapter().getItem(position);//这里问题
double lon = poi.getLatLonPoint().getLongitude();
}
});
}
private void search(String keyword) {
// TODO Auto-generated method stub
query = new Query(keyword, null, city_curr); //搜索定位城市
query.setPageSize(10);
query.setPageNum(1);
//查询兴趣点
search = new PoiSearch(this, query);
search.setOnPoiSearchListener(this);
search.searchPOIAsyn();
}
@Override
public void onPoiItemDetailSearched(PoiItemDetail arg0, int arg1) {//setOnPoiSearchListener
// TODO Auto-generated method stub
System.out.println("onPoiItemDetailSearched调用了");
}
@Override
public void onPoiSearched(PoiResult poiResult, int rCode) {//setOnPoiSearchListener
// TODO Auto-generated method stub
System.out.println("onPoiSearched调用了"+poiResult+"------rCode"+rCode);
List<String> strs = new ArrayList<String>();
ArrayList<PoiItem> items = poiResult.getPois();
if (items != null && items.size() > 0) {
PoiItem item = null;
for (int i = 0, count = items.size(); i < count; i++) {
item = items.get(i);
strs.add(item.getTitle());
}
// 给ListView赋值,显示结果
ArrayAdapter<String> array = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, strs);
pListView.setAdapter(array);
}
}
}