当前位置:  编程技术>移动开发
本页文章导读:
    ▪展示隐藏软键盘        显示隐藏软键盘 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());
    }

    
[3] google map中施用多种图钉来标示地点
    来源: 互联网  发布时间: 2014-02-18
google map中使用多种图钉来标示地点
如题:要在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

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3