- /**
- * 初始化下拉框
- *
- * @param par 父控件
- */
- private void popWindow(final View par) {
- if (pWindow == null) {
- // 布局文件
- View v = LayoutInflater.from(context).inflate(R.layout.list, null);
- list = (ListView) v.findViewById(R.id.list);
- list.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView<?> arg0, View arg1,
- int arg2, long arg3) {
- // R.String.butian代表的是“不填”
- if (datas.get(arg2).toString().equals(context.getString(R.string.butian))) {
- text.setText("");
- } else {
- text.setText(datas.get(arg2).toString()); // 将当前点击的item中的字符串显示出来
- }
- if (pWindow != null) { // 关闭下拉框
- changPopState(par);
- }
- }
- });
- adapter = new OptionsAdapter(context, datas); // 根据数据,设置下拉框显示
- list.setAdapter(adapter);
- list.setDivider(null); // 屏蔽下拉框每个item之间的线条
- /**
- * 两种不同长度的下拉框,主要是为了适应屏幕的大小
- */
- if (p_width > 0) {
- pWindow = new PopupWindow(v, par.getWidth(), 150);
- } else {
- pWindow = new PopupWindow(v, par.getWidth(), 300);
- }
- pWindow.setFocusable(true);
- pWindow.setBackgroundDrawable(new BitmapDrawable());
- pWindow.setOutsideTouchable(true);
- pWindow.update();
- }
- pWindow.showAsDropDown(text);
- }
初始化下拉框
最新推荐文章于 2022-10-24 15:06:04 发布