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

来源:互联网 发布:路由器端口限速设置 编辑:程序博客网 时间:2024/05/16 13:47

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

今天说的是比较简单的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);
 //这个很重要的没有这个 点击popwindow以外的布局pop是不会消失的,本人在此犯了大错切记 
popupWindow.setBackgroundDrawable(new PaintDrawable());
 //获取焦点popupWindow.setFocusable(true);
  //点击popwindow以外的布局让pop消失popupWindow.setOutsideTouchable(true);
  //是在哪个布局(控件)下面(可以修改上下左右的都可以)popupWindow.showAsDropDown(tview);
  //监听 popupWindow消失的监听 popupWindow.setOnDismissListener(new OnDismissListener() {@Overridepublic void onDismiss() { }});listView.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view,int position, long id) {mUp.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.puj));popupWindow.dismiss();tview.setText(name[position]);}});}

0 0