欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android开发中PopupWindow用法实例分析

程序员文章站 2024-02-21 14:48:34
本文实例分析了android开发中popupwindow用法。分享给大家供大家参考,具体如下: private textview tv_appmanager_ti...

本文实例分析了android开发中popupwindow用法。分享给大家供大家参考,具体如下:

private textview tv_appmanager_title;
private listview lv_app_manager;
private linearlayout ll_appmanager_loading;
private appmanagerprovider provider;
private list<appmanagerinfo> infos ;
private appmanageradapter adapter;
private popupwindow localpopupwindow;
private handler handler = new handler(){
  public void handlemessage(android.os.message msg) {
    switch (msg.what) {
    case constants.msg_app_manager:
      ll_appmanager_loading.setvisibility(view.invisible);
      adapter = new appmanageradapter(infos, appmanageractivity.this);
      lv_app_manager.setadapter(adapter);
      break;
    }
  };
};
@override
protected void oncreate(bundle savedinstancestate) {
  super.oncreate(savedinstancestate);
  setcontentview(r.layout.appmanager);
  lv_app_manager = (listview) this.findviewbyid(r.id.lv_app_manager);
  ll_appmanager_loading = (linearlayout) this.findviewbyid(r.id.ll_appmanager_loading);
  ll_appmanager_loading.setvisibility(view.visible);
  new thread(){
    public void run() {
      provider = new appmanagerprovider(appmanageractivity.this);
      infos = provider.getappmanagerinfo();
      message msg = new message();
      msg.what = constants.msg_app_manager;
      handler.sendmessage(msg);
    };
  }.start();
  lv_app_manager.setonitemclicklistener(new onitemclicklistener() {
    @override
    public void onitemclick(adapterview<?> parent, view view,
        int position, long id) {
      if(null != localpopupwindow){
        localpopupwindow.dismiss();
        localpopupwindow = null;
      }
      int [] location = new int[2];
      view.getlocationinwindow(location);
      int x = location[0] + 60;
      int y = location[1];
      textview tv = new textview(appmanageractivity.this);
      appmanagerinfo info = (appmanagerinfo) lv_app_manager.getitematposition(position);
      tv.settext(info.getpackname());
      tv.settextsize(20);
      tv.settextcolor(color.red);
      localpopupwindow = new popupwindow(tv, layoutparams.wrap_content, layoutparams.wrap_content);
      drawable background = new colordrawable(color.gray);
      localpopupwindow.setbackgrounddrawable(background);
      localpopupwindow.showatlocation(tv, 51, x, y);
    }
  });
  lv_app_manager.setonscrolllistener(new onscrolllistener() {
    @override
    public void onscrollstatechanged(abslistview view, int scrollstate) {
      if(null != localpopupwindow){
        localpopupwindow.dismiss();
        localpopupwindow = null;
      }
    }
    @override
    public void onscroll(abslistview view, int firstvisibleitem,
        int visibleitemcount, int totalitemcount) {
      if(null != localpopupwindow){
        localpopupwindow.dismiss();
        localpopupwindow = null;
      }
    }
  });
}

更多关于android相关内容感兴趣的读者可查看本站专题:《android开发入门与进阶教程》、《android通信方式总结》、《android基本组件用法总结》、《android视图view技巧总结》、《android布局layout技巧总结》及《android控件用法总结

希望本文所述对大家android程序设计有所帮助。