初始化下拉框

  1. /** 
  2.      * 初始化下拉框 
  3.      * 
  4.      * @param par 父控件 
  5.      */  
  6.     private void popWindow(final View par) {  
  7.         if (pWindow == null) {  
  8.   
  9.             // 布局文件  
  10.             View v = LayoutInflater.from(context).inflate(R.layout.list, null);  
  11.             list = (ListView) v.findViewById(R.id.list);  
  12.             list.setOnItemClickListener(new OnItemClickListener() {  
  13.                 public void onItemClick(AdapterView<?> arg0, View arg1,  
  14.                                         int arg2, long arg3) {  
  15.                     // R.String.butian代表的是“不填”  
  16.                     if (datas.get(arg2).toString().equals(context.getString(R.string.butian))) {    
  17.                         text.setText("");  
  18.                     } else {  
  19.                         text.setText(datas.get(arg2).toString()); // 将当前点击的item中的字符串显示出来  
  20.                     }  
  21.                     if (pWindow != null) { // 关闭下拉框  
  22.                         changPopState(par);  
  23.                     }  
  24.                 }  
  25.             });  
  26.             adapter = new OptionsAdapter(context, datas); // 根据数据,设置下拉框显示  
  27.             list.setAdapter(adapter);  
  28.             list.setDivider(null); // 屏蔽下拉框每个item之间的线条  
  29.             /** 
  30.              * 两种不同长度的下拉框,主要是为了适应屏幕的大小 
  31.              */  
  32.             if (p_width > 0) {  
  33.                 pWindow = new PopupWindow(v, par.getWidth(), 150);  
  34.             } else {  
  35.                 pWindow = new PopupWindow(v, par.getWidth(), 300);  
  36.             }  
  37.             pWindow.setFocusable(true);  
  38.             pWindow.setBackgroundDrawable(new BitmapDrawable());  
  39.             pWindow.setOutsideTouchable(true);  
  40.             pWindow.update();  
  41.         }  
  42.         pWindow.showAsDropDown(text);  
  43.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值