当前位置: 编程技术>移动开发
本页文章导读:
▪展示隐藏软键盘 显示隐藏软键盘
public void showInput(boolean flag){
InputMethodManager imm = (InputMethodManager)
etSearch.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (flag == true){
imm.showSoftInput(etSearch, 0); //.........
▪ 干掉进程 杀死进程
重写onDestroy方法可以杀掉程序的进程,彻底释放资源.(如果你想节省下次打开这个程序的时间就不要杀了) @Override protected void onDestroy() { super.onDestroy(); .........
▪ google map中施用多种图钉来标示地点 google map中使用多种图钉来标示地点
如题:要在google 地图中使用多种图钉来表示地点的不同状态,如红色图钉表示可用,黑色表示不可用等。找到一示例,是google论坛上的例子(http://groups.google..........
[1]展示隐藏软键盘
来源: 互联网 发布时间: 2014-02-18
显示隐藏软键盘
public void showInput(boolean flag){ InputMethodManager imm = (InputMethodManager) etSearch.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (flag == true){ imm.showSoftInput(etSearch, 0); //显示软键盘 }else{ imm.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);//隐藏软键盘 } }
[2] 干掉进程
来源: 互联网 发布时间: 2014-02-18
杀死进程
重写onDestroy方法可以杀掉程序的进程,彻底释放资源.(如果你想节省下次打开这个程序的时间就不要杀了)
@Override
protected void onDestroy() {
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
}
重写onDestroy方法可以杀掉程序的进程,彻底释放资源.(如果你想节省下次打开这个程序的时间就不要杀了)
@Override
protected void onDestroy() {
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
}
[3] google map中施用多种图钉来标示地点
来源: 互联网 发布时间: 2014-02-18
google map中使用多种图钉来标示地点
如题:要在google 地图中使用多种图钉来表示地点的不同状态,如红色图钉表示可用,黑色表示不可用等。找到一示例,是google论坛上的例子(http://groups.google.com/group/android-developers/browse_thread/thread/60666b7dae3f77b8)
源码如下:
整个项目链接:https://github.com/commonsguy/cw-advandroid/tree/master/Maps/ILuvNooYawk
如题:要在google 地图中使用多种图钉来表示地点的不同状态,如红色图钉表示可用,黑色表示不可用等。找到一示例,是google论坛上的例子(http://groups.google.com/group/android-developers/browse_thread/thread/60666b7dae3f77b8)
源码如下:
public class NooYawk extends MapActivity { private MapView map=null; private MyLocationOverlay me=null; private SitesOverlay sites=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); map=(MapView)findViewById(R.id.map); map.getController().setCenter(getPoint(40.76793169992044, -73.98180484771729)); map.getController().setZoom(17); map.setBuiltInZoomControls(true); sites=new SitesOverlay(); map.getOverlays().add(sites); me=new MyLocationOverlay(this, map); map.getOverlays().add(me); } @Override public void onResume() { super.onResume(); me.enableCompass(); } @Override public void onPause() { super.onPause(); me.disableCompass(); } @Override protected boolean isRouteDisplayed() { return(false); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_S) { map.setSatellite(!map.isSatellite()); return(true); } else if (keyCode == KeyEvent.KEYCODE_Z) { map.displayZoomControls(true); return(true); } else if (keyCode == KeyEvent.KEYCODE_H) { sites.toggleHeart(); return(true); } return(super.onKeyDown(keyCode, event)); } private GeoPoint getPoint(double lat, double lon) { return(new GeoPoint((int)(lat*1000000.0), (int)(lon*1000000.0))); } private class SitesOverlay extends ItemizedOverlay<CustomItem> { private Drawable heart=null; private List<CustomItem> items=new ArrayList<CustomItem>(); private PopupPanel panel=new PopupPanel(R.layout.popup); public SitesOverlay() { super(null); heart=getMarker(R.drawable.heart_full); items.add(new CustomItem(getPoint(40.748963847316034, -73.96807193756104), "UN", "United Nations", getMarker(R.drawable.blue_full_marker), heart)); items.add(new CustomItem(getPoint(40.76866299974387, -73.98268461227417), "Lincoln Center", "Home of Jazz at Lincoln Center", getMarker(R.drawable.orange_full_marker), heart)); items.add(new CustomItem(getPoint(40.765136435316755, -73.97989511489868), "Carnegie Hall", "Where you go with practice, practice, practice", getMarker(R.drawable.green_full_marker), heart)); items.add(new CustomItem(getPoint(40.70686417491799, -74.01572942733765), "The Downtown Club", "Original home of the Heisman Trophy", getMarker(R.drawable.purple_full_marker), heart)); populate(); } @Override protected CustomItem createItem(int i) { return(items.get(i)); } @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, shadow); } @Override protected boolean onTap(int i) { OverlayItem item=getItem(i); GeoPoint geo=item.getPoint(); Point pt=map.getProjection().toPixels(geo, null); View view=panel.getView(); ((TextView)view.findViewById(R.id.latitude)) .setText(String.valueOf(geo.getLatitudeE6()/1000000.0)); ((TextView)view.findViewById(R.id.longitude)) .setText(String.valueOf(geo.getLongitudeE6()/1000000.0)); ((TextView)view.findViewById(R.id.x)) .setText(String.valueOf(pt.x)); ((TextView)view.findViewById(R.id.y)) .setText(String.valueOf(pt.y)); panel.show(pt.y*2>map.getHeight()); return(true); } @Override public int size() { return(items.size()); } void toggleHeart() { CustomItem focus=getFocus(); if (focus!=null) { focus.toggleHeart(); } map.invalidate(); } private Drawable getMarker(int resource) { Drawable marker=getResources().getDrawable(resource); marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); boundCenter(marker); return(marker); } } class PopupPanel { View popup; boolean isVisible=false; PopupPanel(int layout) { ViewGroup parent=(ViewGroup)map.getParent(); popup=getLayoutInflater().inflate(layout, parent, false); popup.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { hide(); } }); } View getView() { return(popup); } void show(boolean alignTop) { RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); if (alignTop) { lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); lp.setMargins(0, 20, 0, 0); } else { lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lp.setMargins(0, 0, 0, 60); } hide(); ((ViewGroup)map.getParent()).addView(popup, lp); isVisible=true; } void hide() { if (isVisible) { isVisible=false; ((ViewGroup)popup.getParent()).removeView(popup); } } } class CustomItem extends OverlayItem { Drawable marker=null; boolean isHeart=false; Drawable heart=null; CustomItem(GeoPoint pt, String name, String snippet, Drawable marker, Drawable heart) { super(pt, name, snippet); this.marker=marker; this.heart=heart; } @Override public Drawable getMarker(int stateBitset) { Drawable result=(isHeart ? heart : marker); setState(result, stateBitset); return(result); } void toggleHeart() { isHeart=!isHeart; } } }
整个项目链接:https://github.com/commonsguy/cw-advandroid/tree/master/Maps/ILuvNooYawk
最新技术文章: