android popupWindow的运用
来源:互联网 发布:淘宝网地摊用衣架 编辑:程序博客网 时间:2024/05/16 14:56
PopupWindow是android中用户比较喜欢的一个控件,运用起来也比较简单,新浪微博客户端中就用到PopupWindow来选择好友分类。
今天我们做的就是它了,popupWindow里放一个ListView。
首先我们看到popupWindow里是一个listView,我们用布局实现这个ListView:
<?xml version="1.0"encoding="UTF-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:id = "@+id/popupLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#aa000000"> <ListView android:id="@+id/customer_popuplist" android:layout_width="fill_parent" android:layout_height="fill_parent"/></LinearLayout>
然后我们就将他实例化并添加到PopupWindow里:
button =(Button)findViewById(R.id.button); button.setOnClickListener(newView.OnClickListener() { @Override publicvoid onClick(View v) { //TODO Auto-generated method stub showPopup(); } }); } private void showPopup(){ //listview的显示条目内容 friends= new String[]{"全部","我的微博","周边","未命名","未命名非公有","hhv"}; //得到popupWindow的显示布局 Viewview =LayoutInflater.from(PopupWindowTestActivity.this).inflate(R.layout.popup,null); LinearLayout popuplayout =(LinearLayout)view.findViewById(R.id.popupLayout); //实例化listview并设置适配器 ListView list =(ListView)view.findViewById(R.id.customer_popuplist); list.setAdapter(newArrayAdapter<String>(PopupWindowTestActivity.this,android.R.layout.simple_list_item_1,friends)); //实例化并设置popup属性 popup = newPopupWindow(popuplayout,180,220);//popup的布局及长宽 //强行获得popupWindow里面的内容的焦点(ListView),如果设为false,listView将得不到焦点,点击listview也没有反应 popup.setFocusable(true); //PopupWindow显示在button下面 popup.showAsDropDown(button,70,0);//第二个参数是离button左边100px,0是离button底部0px list.setOnItemClickListener(newOnItemClickListener() { @Override publicvoid onItemClick(AdapterView<?> parent, View v, intposition, long id) { button.setText(friends[position]); popup.dismiss(); popup= null; } }); }
好了 让我们看一下效果图
popupWindow的基本实现就这样了,若要做的更美观,就得在布局上下些功夫了! ! 呵呵,就说到这里吧,再见!!
- android popupWindow的运用
- 【Android】PopupWindow的简单运用
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- android PopupWindow的用法
- Android PopupWindow的使用!!!
- Android PopupWindow 的使用
- Android PopupWindow的使用
- Android PopupWindow的焦点
- android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow 的使用
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用
- android popupwindow的实现
- 防止ListView变色
- IPv6套接字编程介绍
- JavaFX2.0基础教程 之 架构和框架
- Android JNI开发入门篇/提高篇/进阶篇 (三篇合一)
- linux目录结构及主要内容
- android popupWindow的运用
- 详解CCProgressTimer 进度条并修改cocos2d源码实现“理想”游戏进度条!
- Tooltip配置
- AAC音频编码规格
- This system is not registered with RHN问题的解决
- Linux 共享库 /etc/ld.so.conf文件
- poj3003&2397 DP 记录路径
- 手机产品设计禁忌
- 十年程序苦旅