0

我正在编写一个在警报对话框中显示 2 个按钮的应用程序,一个用于选择对象,另一个用于显示详细信息。

我评估带有所选新项目的地图是否具有值,但即使清除地图,条件也总是返回假。

这是我调用对话框的 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;
4

1 回答 1

0

这是缓存对话的问题。

我不知道那个对话框被缓存在android中。

为了解决这个问题,我添加了:

removeDialog(CONTEXT_MENU_SELECT);

AEP41Activity.this.showDialog(CONTEXT_MENU_SELECT);

于 2013-06-06T10:23:00.117 回答