switch语句中的toast一直不消失
@Override
public boolean onOptionsItemSelected(MenuItem item) {
mDrawerToggle.onOptionsItemSelected(item);
// TODO 自动生成的方法存根
switch(item.getItemId()){
case 1:
mBaiduMap = mMapView.getMap();
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
mLocClient = new LocationClient(getApplicationContext());
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打开gps
option.setCoorType("bd09ll"); // 设置坐标类型
option.setScanSpan(1000);
mLocClient.setLocOption(option);
mLocClient.start();
mCurrentMode = LocationMode.NORMAL;
mLocClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if (location == null) {
return;
}
StringBuffer sb = new StringBuffer(256);
sb.append("纬度 : ");
sb.append(location.getLatitude());
sb.append("n经度 : ");
sb.append(location.getLongitude());
Toast.makeText(NavigationDrawerActivity.this, sb.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivePoi(BDLocation location) {finish();
}
});
mBaiduMap
.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, mCurrentMarker));
break;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
public class NavigationDrawerActivity extends Activity implements
AdapterView.OnItemClickListener {
private DrawerLayout mDrawerLayout;
// private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mCityNames;
private int[] mCityImages;
private LinearLayout left_drawer;
private ListView lv_pos;
MapView mMapView = null;
LocationClient mLocClient;
BaiduMap mBaiduMap;
public MyLocationListenner myListener = new MyLocationListenner();
boolean isFirstLoc =true;// 是否首次定位
private LocationMode mCurrentMode;
BitmapDescriptor mCurrentMarker;
layout geolay;
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView
(R.layout.activity_navigation_drawer);
mMapView = (MapView) findViewById(R.id.bmapView);
left_drawer = (LinearLayout) findViewById(R.id.left_drawer);// 左侧控件
lv_pos = (ListView) findViewById(R.id.lv_pos);
mTitle = mDrawerTitle = getTitle();//这里获取---没搞懂,哪位大神看到了 麻烦回下贴
mCityNames = getResources().getStringArray(R.array.drawer_items);// 城市数据,从XML文件中获取到的数组内容
TypedArray typedArray = getResources().obtainTypedArray(
R.array.city_images);
mCityImages = new int[typedArray.length()];
for (int i = 0; i < typedArray.length(); ++i) {
mCityImages[i] = typedArray.getResourceId(i, 0);
}
typedArray.recycle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
// mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
// mDrawerList.setAdapter(new ArrayAdapter<String>(this,
// R.layout.drawer_list_item, mCityNames));
lv_pos.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mCityNames));
lv_pos.setOnItemClickListener(this);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open,
R.string.drawer_close) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {// 当内容为空的时候默认启动的页面
selectItem(0);
}
}
@Override
protected void onDestroy() {
if (mLocClient!=null) {
mLocClient.stop();
}
//
// // 关闭定位图层
// mBaiduMap.setMyLocationEnabled(false);
// mMapView.onDestroy();
// mMapView = null;
super.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
//在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
//在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理
mMapView.onPause();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
mDrawerToggle.onOptionsItemSelected(item);
// TODO 自动生成的方法存根
switch(item.getItemId()){
case 1:
mBaiduMap = mMapView.getMap();
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
mLocClient = new LocationClient(getApplicationContext());
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打开gps
option.setCoorType("bd09ll"); // 设置坐标类型
option.setScanSpan(1000);
mLocClient.setLocOption(option);
mLocClient.start();
mCurrentMode = LocationMode.NORMAL;
mLocClient.registerLocationListener(new BDLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if (location == null) {
return;
}
StringBuffer sb = new StringBuffer(256);
sb.append("纬度 : ");
sb.append(location.getLatitude());
sb.append("n经度 : ");
sb.append(location.getLongitude());
Toast.makeText(NavigationDrawerActivity.this, sb.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivePoi(BDLocation location) {finish();
}
});
mBaiduMap
.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, mCurrentMarker));
break;
case 2:
mBaiduMap = mMapView.getMap();
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
mLocClient = new LocationClient(getApplicationContext());
mLocClient.registerLocationListener(myListener);
LocationClientOption option1 = new LocationClientOption();
option1.setOpenGps(true);// 打开gps
option1.setCoorType("bd09ll"); // 设置坐标类型
option1.setScanSpan(1000);
mLocClient.setLocOption(option1);
mLocClient.start();
mCurrentMode = LocationMode.FOLLOWING;
mBaiduMap
.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, mCurrentMarker));
break;
case 3:
Intent intent = new Intent(this, Offline.class);
startActivity(intent);
// finish();
break;
}
return false;
//return super.onOptionsItemSelected(item);
}
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// return mDrawerToggle.onOptionsItemSelected(item)
// || super.onOptionsItemSelected(item);
// }
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
selectItem(position);
}
private void selectItem(int position) {// 选中
Fragment fragment = new SampleFragment();
FragmentManager fragmentManager = getFragmentManager();
Bundle args = new Bundle();
switch(position){
case 0:args.putInt(SampleFragment.ARG_IMAGE_RES, mCityImages[position]);
args.putInt(SampleFragment.ARG_ACTION_BG_RES, R.drawable.drawer_shadow);
fragment.setArguments(args);
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment).commit();
lv_pos.setItemChecked(position, true);// Listview被选中时候设置的背景色
setTitle(mCityNames[position]);
mDrawerLayout.closeDrawer(left_drawer);
break;
case 1:
Intent geo = new Intent(this, GeoCoderDemo.class);
startActivity(geo);
break;
case 2:Intent poi = new Intent(this, PoiSearchDemo.class);
startActivity(poi);
break;
case 3:Intent route = new Intent(this, RoutePlanDemo.class);
startActivity(route);
break;
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
SubMenu subMenu = menu.addSubMenu("action item");
subMenu.add(0, 1, 0, "定位").setIcon(R.drawable.indoor_loc_suc);;
subMenu.add(0, 2, 0, "跟随").setIcon(R.drawable.icon_track_mark_focus);
subMenu.add(0, 3, 0, "离线地图 ").setIcon(R.drawable.icon_realtime_select);
MenuItem menuItem = subMenu.getItem();
menuItem.setIcon(R.drawable.track_point_bubble);
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return super.onCreateOptionsMenu(menu);
}
public class MyLocationListenner implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
// map view 销毁后不在处理新接收的位置
if (location == null || mMapView == null)
return;
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此处设置开发者获取到的方向信息,顺时针0-360
.direction(100).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData);
if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(location.getLatitude(),
location.getLongitude());
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
mBaiduMap.animateMapStatus(u);
}
}
public void onReceivePoi(BDLocation poiLocation) {
}
}
就是你点击屏幕一下,就消失一下 ,但是过一会又显示了
Toast
的显示 跟 手机系统以及 型号都有关系, 可能会产生 细微的差距. 但是不明白 你说的 不消失 是什么意
思.