private void initDatas() { code = SearchFragment.positionsClassCode; value = SearchFragment.positionsClassValue; if (PositionClassifyController.positionClassifies != null && PositionClassifyController.positionClassifies.size() > 0) { int n = PositionClassifyController.positionClassifies.size(); for (int i = 0; i < n; i++) { final PositionClassify positionClassify = PositionClassifyController.positionClassifies.get(i); final PositionClassItemView positionView = new PositionClassItemView(context); positionView.setPositionClassify(positionClassify); positionView.setOnItemClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (positionClassify.isHasSub()) { showSubAddressViews(positionClassify); } else { boolean flag = positionView.getCheckedStatus(); positionView.setCheckedStatus(!flag); if (!flag) { code = positionClassify.getCode(); value = positionClassify.getValue(); startIntent(); finish(); } else { code = ""; value = ""; } } } }); linear_main.addView(positionView); if (i < n - 1) { View line = LayoutInflater.from(context).inflate(R.layout.layout_line, null); linear_main.addView(line, params); } else { params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = 1; params.leftMargin = 1; params.bottomMargin = 10; View line = LayoutInflater.from(context).inflate(R.layout.layout_line, null); linear_main.addView(line, params); } } } }
/** * 加载子控件 * * <pre>方法 </pre> * * @param area 地区 */ private void showSubAddressViews(PositionClassify positionClassify) { params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = 1; params.leftMargin = 40; if (null != linear_sub && linear_sub.getChildCount() > 0) { linear_sub.removeAllViews(); } if (positionClassify != null) { List<PositionClassify> pList = positionClassify.getSubList(); if (pList != null && pList.size() > 0) { if (!pList.get(0).getCode().equals(positionClassify.getCode())) { PositionClassify pp = new PositionClassify(); pp.setCode(positionClassify.getCode()); pp.setPcode(positionClassify.getPcode()); pp.setHasSub(false); pp.setSubList(null); pp.setValue(positionClassify.getValue()); pList.add(0, pp); } int nn = pList.size(); for (int i = 0; i < nn; i++) { final PositionClassify p = pList.get(i); if (p != null) { final PositionClassItemView itemView = new PositionClassItemView(context); itemView.setPositionClassify(p); itemView.setOnItemClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (p.isHasSub()) { } else { boolean flag = itemView.getCheckedStatus(); itemView.setCheckedStatus(!flag); if (!flag) { code = p.getCode(); value = p.getValue(); startIntent(); finish(); } else { code = ""; value = ""; } } } }); linear_sub.addView(itemView); if (i < nn - 1) { View line = LayoutInflater.from(context).inflate(R.layout.layout_line, null); linear_sub.addView(line, params); } else { params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.height = 1; params.leftMargin = 1; View line = LayoutInflater.from(context).inflate(R.layout.layout_line, null); linear_sub.addView(line, params); } } } scroll_page_sub.setAnimation(animation_in); scroll_page_sub.startAnimation(animation_in); } } }