popupWindow = new PopupWindow(this);
View view = LayoutInflater.from(this).inflate(R.layout.popup_layout, null);
leftLV = (ListView) view.findViewById(R.id.pop_listview_left);
rightLV = (ListView) view.findViewById(R.id.pop_listview_right);
popupWindow.setContentView(view);
popupWindow.setBackgroundDrawable(new PaintDrawable());
popupWindow.setFocusable(true);
popupWindow.setHeight(ScreenUtils.getScreenH(this) * 2 / 3);
popupWindow.setWidth(ScreenUtils.getScreenW(this));
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
darkView.startAnimation(animOut);
darkView.setVisibility(View.GONE);
leftLV.setSelection(0);
rightLV.setSelection(0);
}
});
//左侧ListView点击事件
leftLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//二级数据
List<SecondClassItem> list2 = firstList.get(position).getSecondList();
//如果没有二级类,则直接跳转
if (list2 == null || list2.size() == 0) {
popupWindow.dismiss();
int firstId = firstList.get(position).getId();
String selectedName = firstList.get(position).getName();
handleResult(firstId, -1, selectedName);
return;
}
FirstClassAdapter adapter = (FirstClassAdapter) (parent.getAdapter());
//如果上次点击的就是这一个item,则不进行任何操作
if (adapter.getSelectedPosition() == position){
return;
}
//根据左侧一级分类选中情况,更新背景色
adapter.setSelectedPosition(position);
adapter.notifyDataSetChanged();
//显示右侧二级分类
updateSecondListView(list2, secondAdapter);
}
});
//右侧ListView点击事件
rightLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//关闭popupWindow,显示用户选择的分类
popupWindow.dismiss();
int firstPosition = firstAdapter.getSelectedPosition();
int firstId = firstList.get(firstPosition).getId();
int secondId = firstList.get(firstPosition).getSecondList().get(position).getId();
String selectedName = firstList.get(firstPosition).getSecondList().get(position)
.getName();
handleResult(firstId, secondId, selectedName);
}
});
if (popupWindow.isShowing()) {
popupWindow.dismiss();
} else {
popupWindow.showAsDropDown(findViewById(R.id.main_div_line));
popupWindow.setAnimationStyle(-1);
//背景变暗
darkView.startAnimation(animIn);
darkView.setVisibility(View.VISIBLE);
}
//刷新右侧ListView
private void updateSecondListView(List<SecondClassItem> list2,
SecondClassAdapter secondAdapter) {
secondList.clear();
secondList.addAll(list2);
secondAdapter.notifyDataSetChanged();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有