public RecordsetAdapter(Recordset recordset) { mRecordset = recordset; mFieldInfos = mRecordset.getFieldInfos(); point = mRecordset.getGeometry().getInnerPoint(); }
@Override public View getChildView( int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { TextView holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.list_queryresult_item, null); holder = (TextView) convertView.findViewById(R.id.tv_name); convertView.setTag(holder); } else { holder = (TextView) convertView.getTag(); } try { final Recordset recordset = mResultData.get(groupPosition); recordset.moveTo(childPosition); String fieldName = "Name"; // 这个字段一定存在 Geometry geometry = recordset.getGeometry(); if (geometry.getType() == GeometryType.GEOREGION) { fieldName = "SMID"; } // 得先找一下哪个字段合适 FieldInfos finfos = recordset.getFieldInfos(); for (int i = 0; i < finfos.getCount(); i++) { if ((finfos.get(i).getName().contains("name") || finfos.get(i).getName().contains("NAME")) && finfos.get(i).getType() == FieldType.TEXT) { fieldName = finfos.get(i).getName(); break; } } final Object obj = recordset.getFieldValue(fieldName); holder.setText(obj == null ? "null" : obj.toString()); convertView.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { recordset.moveTo(childPosition); Geometry geometry = recordset.getGeometry(); if (geometry.getType() == GeometryType.GEOREGION) { GeoStyle geostyle = new GeoStyle(); geostyle.setFillForeColor(new com.supermap.data.Color(255, 0, 0)); geostyle.setFillOpaqueRate(30); geostyle.setLineColor(new com.supermap.data.Color(180, 180, 200)); geostyle.setLineWidth(0.4); geometry.setStyle(geostyle); int index = mTrackingLayer.indexOf("dypt"); if (index >= 0) mTrackingLayer.remove(index); mTrackingLayer.add(geometry, "dypt"); mMapControl.getMap().refresh(); } if (geometry.getType() == GeometryType.GEOLINE) { GeoStyle geostyle = new GeoStyle(); geostyle.setLineColor(new com.supermap.data.Color(255, 0, 0)); geostyle.setLineWidth(1); geometry.setStyle(geostyle); int index = mTrackingLayer.indexOf("dypt"); if (index >= 0) mTrackingLayer.remove(index); mTrackingLayer.add(geometry, "dypt"); mMapControl.getMap().refresh(); } mDynView.clear(); mMapView.removeAllCallOut(); final CallOut calloutLocation = new CallOut(mMapView.getContext()); calloutLocation.setStyle(CalloutAlignment.BOTTOM); calloutLocation.setLocation( geometry.getInnerPoint().getX(), geometry.getInnerPoint().getY()); calloutLocation.setCustomize(true); // 设置自定义背景 ImageView imageView = new ImageView(mMapControl.getContext()); // 显示起点 imageView.setBackgroundResource(R.drawable.ic_btn_poi); calloutLocation.setContentView(imageView); calloutLocation.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { CallOut checkedCallOut = mMapView.getCallOut("POI"); if (checkedCallOut != null) return; CallOut callout = new CallOut(mMapView.getContext()); callout.setStyle(CalloutAlignment.LEFT); callout.setBackground(Color.WHITE, Color.WHITE); callout.setLocation( calloutLocation.getLocationX(), calloutLocation.getLocationY()); View calloutView = mInflater.inflate(R.layout.callout, null); TextView name = (TextView) calloutView.findViewById(R.id.tv_name); name.setText(obj == null ? "null" : obj.toString()); calloutView .findViewById(R.id.btn_close) .setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { mMapView.removeCallOut("POI"); mMapView.refresh(); } }); ListView list = (ListView) calloutView.findViewById(R.id.list_record); list.setAdapter(new RecordsetAdapter(recordset)); callout.setContentView(calloutView); mMapView.addCallout(callout, "POI"); mMapView.refresh(); } }); mMapView.addCallout(calloutLocation, "Locate"); mDynView.refresh(); mMapControl.panTo(geometry.getInnerPoint(), 300); } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return convertView; }