PopupWindow+ListView

Posted 碎冰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PopupWindow+ListView相关的知识,希望对你有一定的参考价值。

1. 获取打到数据

for (int i = 0; i < iocOutMakeMaterialSubmit.data.size(); i++) {
dataListPopupWindow.add(iocOutMakeMaterialSubmit.data.get(i));
}
initPopupWindow();

2. 初始化

/**
* 创建PopupWindow
*/
protected void initPopupWindow() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
View contentView = inflater.inflate(R.layout.popupwindow_ioc_out_make_material_submit, null);
ListView listView = (ListView) contentView.findViewById(R.id.list_view_submit_popwin);
adapterPopupwindow = new AdapterPopupWindow(getActivity(), R.layout.item_list_ioc_out_make_material_submit, dataListPopupWindow);
listView.setAdapter(adapterPopupwindow);
//item 的点击事件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
IOCOutMakeMaterialSubmit.Data data = dataListPopupWindow.get(i);
dataList.add(data);
adapterListView.notifyDataSetChanged();
closePopupWindow();
reset();
}
});
// PopupWindow实例化
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, true);
popupWindow.setAnimationStyle(R.style.MenuAnimationFade);
// 弹出窗口显示内容视图,默认以锚定视图的左下角为起点,这里为点击按钮
popupWindow.showAtLocation(submitBtn, Gravity.CENTER, 0, 0);
//获取最底层窗口的参数,背景变灰色效果
WindowManager.LayoutParams params = getActivity().getWindow().getAttributes();
params.alpha = 0.5f;
getActivity().getWindow().setAttributes(params);
}

3.关闭窗口

/**
* 关闭窗口
*/
private void closePopupWindow() {
if (popupWindow != null && popupWindow.isShowing()) {
popupWindow.dismiss();
popupWindow = null;
WindowManager.LayoutParams params = getActivity().getWindow().getAttributes();
params.alpha = 1f;
getActivity().getWindow().setAttributes(params);
}
}

 

以上是关于PopupWindow+ListView的主要内容,如果未能解决你的问题,请参考以下文章

Android 仿美团下拉(PopupWindow)列表(ListView)一二级分类菜单的功能

片段中 ListView 的 setOnItemClickListener

片段中ListView的setOnItemClickListener

PopupWindow的使用

片段中的ListView不显示

在片段中添加 ListView