时间:2021-05-20
本文实例分析了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; } };};@Overrideprotected 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程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了Android编程之PopupWindow隐藏及显示方法。分享给大家供大家参考,具体如下:前面分析了PopupWindow的用法(位置、动画、焦点
参考原文AndroidPopupWindow用法解析进行学习,通过实例及PopupWindow源码分析了PopupWindow的使用。文章最后的“补充Case:
本文实例讲述了Android开发使用PopupWindow实现弹出警告框的复用类。分享给大家供大家参考,具体如下:Android开发中相信下图所示界面大家都不陌
本文实例讲述了Android开发之PopupWindow创建弹窗、对话框的方法。分享给大家供大家参考,具体如下:简介:PopupWindow可创建类似对话框风格
本文实例分析了Android开发之TimePicker控件用法。分享给大家供大家参考,具体如下:新建项目:NewAndroidProject->Projectn