我正在编写一个应用程序,在警告对话框中显示2个按钮,一个用于选择对象,另一个用于显示详细信息。
我评估选择了新项目的地图是否具有值,但是,即使清除地图,条件也始终返回false。
以下是我调用对话框的OnCreateDialog()和AsyncTask的代码:
// Map Containing the objects already selected
Map<String, IdentifyResult> itemsSelected = new HashMap<String, IdentifyResult>();
// Map Containing the new objects selected
Map<String, IdentifyResult> longClickTemp = new HashMap<String, IdentifyResult>();
protected class IdentifyFeatures extends
AsyncTask<IdentifyParameters, Void, IdentifyResult[]> {
IdentifyTask identifier;
ProgressDialog progress;
@Override
protected IdentifyResult[] doInBackground(IdentifyParameters... params) {
IdentifyResult[] result = null;
if (params != null && params.length > 0) {
IdentifyParameters usedParams = params[0];
try {
result = identifier.execute(usedParams);
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
@Override
protected void onPreExecute() {
identifier = new IdentifyTask(layer2.getUrl());
progress=ProgressDialog.show(AEP41Activity.this, "Chargement", "Récupération de la sélection");
super.onPreExecute();
}
@Override
protected void onPostExecute(IdentifyResult[] result) {
if (result != null && result.length > 0) {
Toast t = Toast.makeText(AEP41Activity.this, result.length
+ " objects trouves", Toast.LENGTH_SHORT);
t.show();
AEP41Activity.this.longClickTemp.clear();
// Highlight features selected
for (int i = 0; i < result.length; i++) {
// Verify if the object is already selected
if (itemsSelected.containsKey(result[i].getAttributes()
.get("OBJECTID"))) {
Log.d("Object Already Exists", "Id: "
+ result[i].getAttributes().get("OBJECTID"));
continue;
}
Log.d("Object Found",
"Object Type: " + result[i].getLayerName()
+ " Id: "
+ result[i].getAttributes().get("OBJECTID"));
AEP41Activity.this.longClickTemp.put(
(String) result[i].getAttributes().get("OBJECTID"),
result[i]);
}
progress.dismiss();
AEP41Activity.this.showDialog(CONTEXT_MENU_SELECT);
} else {
progress.dismiss();
Toast t = Toast.makeText(AEP41Activity.this,
"Aucun objet trouve", Toast.LENGTH_SHORT);
t.show();
}
}
}
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builter = new AlertDialog.Builder(
AEP41Activity.this);
switch (id) {
case CONTEXT_MENU_SELECT:
builter.setTitle("Selectionner Option");
if(!longClickTemp.isEmpty()){
builter.setPositiveButton("Selectionner", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
itemsSelected.putAll(longClickTemp);
updateSelectedMenu();
}
});
}
builter.setNeutralButton("Details", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle b = new Bundle();
b.putStringArrayList("SelectedIds", Utilities.getStringArray(itemsSelected.keySet()));
b.putSerializable("TabValues", Utilities
.getIdentifyResultArray(longClickTemp));
Intent i = new Intent(AEP41Activity.this,
FieldDetails.class);
i.putExtras(b);
startActivity(i);
}
});
break;
答案 0 :(得分:0)
这是缓存对话框的问题。
我不知道对话框是在android中缓存的。
为解决这个问题,我补充道:
removeDialog(CONTEXT_MENU_SELECT);
之前AEP41Activity.this.showDialog(CONTEXT_MENU_SELECT);