我开发了一个带有自定义多边形视图的ViewLabel,我可以很好地显示,但是当我转到另一个Activity(通过startActivityForResult())并返回我的Map Activity时,带一个值来更新此自定义的TextView我像以前一样得到了ViewLabel。我在设置音符数量之前和之后试图使其无效。但是不成功。
你能告诉我我的错误吗?
这是前往另一个活动
之前和之后的方面在这里可以看到其他Activity的Aspect,有4个Notes
我尝试将Note的计数设置为相应的TextView,但它没有显示正确的值
我的onActivityResult代码的日志显示,我可以正确传递值,但View永远不会刷新。
I/WmsMapActivity(13656): onActivityResult:: requestCode: 12
I/WmsMapActivity(13656): onActivityResult:: requestCode: 12 result_ok
I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null
I/WmsMapActivity(13656): onActivityResult:: dataReturnedIntent != null textnote_number: 4
这是代码
...
case Constants.REQUEST_NOTES :
Log.i(TAG, "onActivityResult:: requestCode: "+Constants.REQUEST_NOTES);
if ( resultCode == RESULT_OK) {
Log.i(TAG, "onActivityResult:: requestCode: "+Constants.REQUEST_NOTES+" result_ok");
if (dataReturnedIntent != null) {
Log.i(TAG, "onActivityResult:: dataReturnedIntent != null");
String textnote_number = dataReturnedIntent.getStringExtra(Constants.TEXTNOTES_NUMBER);
Log.i(TAG, "onActivityResult:: dataReturnedIntent != null textnote_number: "+textnote_number);
//textNotesTV.invalidate();
textnotesTV.setText(textnote_number);
//textnotesTV.invalidate();
} else {
Log.i(TAG, "onActivityResult:: dataReturnedIntent == null");
}
} else {
Log.i(TAG, "onActivityResult:: resultCode != RESULT_OK");
}
break;
...
这是我使用相应的Custom ViewLabel
创建Polygon的方法 protected void createPolygon(String id, String fieldguid, String fieldname, String farmguid, String farmname,
PolygonStyle polygonStyle, TextStyle textStyle,
double[][] coordinates, String latitude, String longitude,
int state, int color, ArrayList<HashMap<String, String>> processingHistory,
int bioIndTreatment, String bioindcrop, String bioindboundary, String croptype,
boolean shown) {
// ****************
boolean bioIndBoundaryValue = true, bioIndCropValue = true;
boolean existingBioIndBoundary = true, existingBioIndCrop = true;
ListView history_list_view;
noteParamList = new ArrayList<String>();
noteParamList.add("unclicked"); //0
noteParamList.add(fieldguid); //1
noteParamList.add(fieldname); //2
noteParamList.add(farmguid); //3
noteParamList.add(farmname); //4
noteParamList.add(latitude); //5
noteParamList.add(longitude); //6
noteParamList.add(String.valueOf(color)); //7 color = original_color
Log.i(TAG, "CreatePolygon:note: "+noteParamList.toString());
// We turn into vividsolutions Object, so they provide getArea Method
//
/** User Data **/ // guid
//pol.setId(Long.parseLong(id));
//Log.i(TAG, "CreatePolygon fieldname: "+fieldname + " processingHistory: "+processingHistory);
Projection projGeo = geomLayer.getProjection();
Projection projText = textLayer.getProjection();
ArrayList<MapPos> outerPoses = new ArrayList<MapPos>();
MapPos center = null;
for(double[] coord:coordinates){
outerPoses.add(projGeo.fromWgs84((float)coord[0],(float)coord[1]));
}
//Setting Popup Label if we click the area
LayoutInflater inflater = (LayoutInflater) this.getLayoutInflater();
labelView = inflater.inflate(R.layout.popup_field_newer, null, false);
labelView.setBackgroundColor(Color.WHITE);
// Title - Fieldname
TextView titelTV = (TextView)labelView.findViewById(R.id.popup_fieldname);
titelTV.setTextColor(Color.BLACK);
titelTV.setText(fieldname);
// Croptype
TextView croptypeTV = (TextView)labelView.findViewById(R.id.popup_croptype);
croptypeTV.setTextColor(Color.BLACK);
croptype = ( (croptype != null && croptype.length()>0 ) ? "Croptype: "+croptype:"Croptype: No data");
croptypeTV.setText(croptype);
//Farmname
TextView farmTV = (TextView)labelView.findViewById(R.id.popup_farmname);
farmTV.setTextColor(Color.BLACK);
farmname = "Farm: "+farmname;
farmTV.setText(farmname);
// Area
TextView areaTV = (TextView)labelView.findViewById(R.id.popup_area);
GeometricUtils geomUtils = new GeometricUtils();
double area = geomUtils.computeArea(coordinates);
// Ceiling 2 decimal places
BigDecimal bd = new BigDecimal(area);
BigDecimal roundOff = bd.setScale(2, BigDecimal.ROUND_HALF_EVEN);
area = roundOff.doubleValue();
String areaString = "Area(qm): "+String.valueOf(area);
areaTV.setTextColor(Color.BLACK);
areaTV.setText(areaString);
// Table
ImageView cropIV = (ImageView)labelView.findViewById(R.id.row_crop_value);
ImageView boundaryIV = (ImageView)labelView.findViewById(R.id.row_boundary_value);
ImageView treatmentIV = (ImageView)labelView.findViewById(R.id.row_treatment_value);
int resImgId = 0;
// Bio Ind Treatment
switch (state) {
case 0 : case 1:
resImgId = R.drawable.empty;
break;
case 2 :
if ( bioIndTreatment >= 3 ) {
resImgId = R.drawable.red;
} else if ( bioIndTreatment == 2){
resImgId = R.drawable.ambar;
} else if ( bioIndTreatment == 1 ) {
resImgId = R.drawable.green;
} else if ( bioIndTreatment == 0 ) {
resImgId = R.drawable.empty;
}
break;
}
Log.i(TAG, "CreatePolygon: state: "+state+" fieldname: "+fieldname+" color: "+color +" resImgId: "+resImgId);
Resources res = getResources();
Bitmap bm = BitmapFactory.decodeResource(res, resImgId);
treatmentIV.setImageBitmap(bm);
// Bio Ind Croptype
int resBioIndCrop = R.drawable.no_processed_long_32;
if ( bioindcrop != null && bioindcrop.length()>0 ) {
bioIndCropValue = Boolean.parseBoolean(bioindcrop);
if ( bioIndCropValue ) {
resBioIndCrop = R.drawable.red;
} else {
resBioIndCrop = R.drawable.green;
}
Log.i(TAG, "createPolygon:: fieldname: "+fieldname+", bioIndCropValue: "+bioIndCropValue+" resBioIndCrop: "+resBioIndCrop);
} else {
existingBioIndCrop = false;
}
bm = BitmapFactory.decodeResource(res, resBioIndCrop);
cropIV.setImageBitmap(bm);
// Bio Ind Boundary
int resBioIndBoundary = R.drawable.no_processed_long_32;
if ( bioindboundary != null && bioindboundary.length()>0 ) {
bioIndBoundaryValue = Boolean.parseBoolean(bioindboundary);
if ( bioIndBoundaryValue ) {
resBioIndBoundary = R.drawable.red;
} else {
resBioIndBoundary = R.drawable.green;
}
Log.i(TAG, "createPolygon:: fieldname: "+fieldname+", bioIndboundaryValue: "+bioIndBoundaryValue+" resBioIndBoundary: "+resBioIndBoundary);
} else {
existingBioIndBoundary = false;
}
bm = BitmapFactory.decodeResource(res, resBioIndBoundary);
boundaryIV.setImageBitmap(bm);
// #Notes
HashMap<String, String> settings = session.getSettings();
textnotesTV = (TextView)labelView.findViewById(R.id.popup_textnotes_btn);
setCountNotes(settings, textnotesTV, Constants.TEXTNOTES_NUMBER);
picturenotesTV = (TextView)labelView.findViewById(R.id.popup_picturenotes_btn);
setCountNotes(settings, picturenotesTV, Constants.PICNOTES_NUMBER);
audionotesTV = (TextView)labelView.findViewById(R.id.popup_audionotes_btn);
setCountNotes(settings, audionotesTV, Constants.AUDIONOTES_NUMBER);
videonotesTV = (TextView)labelView.findViewById(R.id.popup_videonotes_btn);
setCountNotes(settings, videonotesTV, Constants.VIDEONOTES_NUMBER);
RelativeLayout relLayoutFieldInfo = (RelativeLayout)labelView.findViewById(R.id.relLayoutFieldInfo);
//relLayoutFieldInfo.setBackgroundColor(color);
// Table Layout
//TableLayout tableLayoutPopupField = (TableLayout)labelView.findViewById(R.id.tableLayoutPopupField);
LabelStyle labelStyle = LabelStyle.builder().setBackgroundColor(Color.WHITE).
setEdgePadding((int) (12 * scale)).
setLinePadding((int) (6 * scale)).
setAlpha(0.85f). // half transparent, half opaque!!!
setTitleFont(Typeface.create("Arial", Typeface.BOLD),16 * scale).
setTitleColor(Color.BLACK).
setTitleAlign(Align.CENTER).
build();
ViewLabel fieldLabel = new ViewLabel(null, labelView, new Handler(), labelStyle );
// Making a resizable View
RelativeLayout relLayout = (RelativeLayout)labelView.findViewById(R.id.relLayoutFieldLabel);
relLayout.setBackgroundColor(Color.WHITE);
relLayout.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
relLayout.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());
// Without holes!
Object obj = null;
Polygon pol = new Polygon(outerPoses, fieldLabel, polygonStyle, noteParamList);
// By Default : all invisible, just if we select one or several will be shown
pol.setVisible(shown);
//
// Attach to geomLayer
geomLayer.add(pol);
myPolygons.add(pol);
//Log.i(TAG,"createPolygon:: #myPolygons: "+myPolygons.size());
double[] _centroid = centroid(pol);
center = projText.fromWgs84(_centroid[0], _centroid[1]);
Text textObj = new Text(center, fieldname, textStyle, null);
textObj.setVisible(false);
myPolygonTexts.add(textObj);
textLayer.add(textObj);
}
布局'popup_field_newer'
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relLayoutFieldInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="@+id/linLayoutFieldInfoHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<TextView
android:id="@+id/popup_fieldname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Fieldname"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="24dp" />
<TextView
android:id="@+id/popup_croptype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_fieldname"
android:layout_below="@+id/popup_fieldname"
android:text="Crop : Triticale"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18dp" />
<TextView
android:id="@+id/popup_farmname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_croptype"
android:layout_below="@+id/popup_croptype"
android:text="Farm: Musterfarm"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18dp" />
<TextView
android:id="@+id/popup_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_farmname"
android:layout_below="@+id/popup_farmname"
android:text="Area(qm): 123.34"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18dp" />
</LinearLayout>
<ImageView
android:id="@+id/popup_sat_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="false"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/linLayoutFieldInfoHeader"
android:src="@drawable/sat_picture_no_available" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relLayoutIndicatorsAndNotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/relLayoutFieldInfo"
android:layout_below="@+id/relLayoutFieldInfo"
android:layout_marginTop="5dp" >
<TextView
android:id="@+id/popup_bioindicators"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/bio_explanation"
android:layout_alignParentRight="true"
android:text="BioIndicators"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18dp" />
<include
android:id="@+id/popup_include_header_indicators"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_bioindicators"
android:layout_alignRight="@+id/bio_explanation"
android:layout_below="@+id/popup_bioindicators"
layout="@layout/header_indicators" />
<include
android:id="@+id/popup_include_value_indicators"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_include_header_indicators"
android:layout_alignRight="@+id/bio_explanation"
android:layout_below="@+id/popup_include_header_indicators"
layout="@layout/value_indicators" />
<ImageView
android:id="@+id/bio_explanation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/popup_include_value_indicators"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="@drawable/history_description_new" />
<TextView
android:id="@+id/popup_textnotes_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/bio_explanation"
android:layout_alignRight="@+id/bio_explanation"
android:layout_below="@+id/bio_explanation"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="Number of Text-Notes: " />
<TextView
android:id="@+id/popup_picturenotes_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_textnotes_btn"
android:layout_alignRight="@+id/popup_textnotes_btn"
android:layout_below="@+id/popup_textnotes_btn"
android:layout_marginBottom="5dp"
android:text="Number of Picture-Notes: " />
<TextView
android:id="@+id/popup_videonotes_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_textnotes_btn"
android:layout_alignRight="@+id/popup_textnotes_btn"
android:layout_below="@+id/popup_picturenotes_btn"
android:layout_marginBottom="5dp"
android:text="Number of Video-Notes: " />
<TextView
android:id="@+id/popup_audionotes_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/popup_textnotes_btn"
android:layout_alignRight="@+id/popup_textnotes_btn"
android:layout_below="@+id/popup_videonotes_btn"
android:layout_marginBottom="5dp"
android:text="Number of Audio-Notes: " />
</RelativeLayout>
答案 0 :(得分:2)
主题在nutiteq-dev列表中讨论:https://groups.google.com/d/msg/nutiteq-dev/bTEb1ScZnbs/ivBTV4-3BgAJ
P.S。通常交叉发布只会造成更多混乱。