首页 > 代码库 > popwindow,弹出框,popwindow点击事件冲突问题很好的解决

popwindow,弹出框,popwindow点击事件冲突问题很好的解决

 尽量自己百度,莫问同事切记切记————最近的感叹,可能太急于求成了,所以以后要有耐心坚决自己搜自己找!!!!

今天说的是比较简单的popwindow,弹出框,这个其实挺简单的主要是有个地方比较可能会出问题就是点击事件

private void initPopWindow(final TextView tview) {
		final String[] name = { "份", "斤", "个", "人", "桌", "只", "半份", "小份", "大份",
				"两", "半只", "锅", "碗", "壶", "打", "瓶", "杯", "听", "罐", "例", "套",
				"串" };
		View contentView = LayoutInflater.from(getActivity()).inflate(
				R.layout.popwindow, null);
		contentView.setBackgroundColor(Color.WHITE);

		popupWindow = new PopupWindow(findViewById(R.id.fl_layout), 159, 250);

		popupWindow.setContentView(contentView);

		TextView textView = (TextView) contentView.findViewById(R.id.text);
		textView.setText("单位");

		ListView listView = (ListView) contentView.findViewById(R.id.list);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, name);
		listView.setAdapter(adapter);
<span style="white-space: pre;">		</span>//这个很重要的没有这个 点击popwindow以外的布局pop是不会消失的,本人在此犯了大错切记 
		popupWindow.setBackgroundDrawable(new PaintDrawable());
 <span style="white-space:pre">		</span>//获取焦点
		popupWindow.setFocusable(true);
 	 //点击popwindow以外的布局让pop消失
		popupWindow.setOutsideTouchable(true);
 	 //是在哪个布局(控件)下面(可以修改上下左右的都可以)
		popupWindow.showAsDropDown(tview);
 	 //监听 popupWindow消失的监听 

		popupWindow.setOnDismissListener(new OnDismissListener() {

			@Override
			public void onDismiss() {
				 
			}
		});

		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				mUp.setImageDrawable(getActivity().getResources()
						.getDrawable(R.drawable.puj));
				popupWindow.dismiss();
				tview.setText(name[position]);
			}
		});
	}

popwindow,弹出框,popwindow点击事件冲突问题很好的解决