Select to view content in your preferred language

querytask problem

688
0
03-05-2017 04:22 AM
mahshidfallah
Deactivated User

hello everybody.

i use querytask sample and it is worked.but i have an error.when i search a place show a toast that tell your place founded but don't change color of feature.how i can fix it??

 this is my code : 

thanks

private class AsyncQueryTask extends AsyncTask<String, Void, FeatureResult> {

    @Override
    protected void onPreExecute() {
        progress = new ProgressDialog(MainActivity.this);

        progress = ProgressDialog.show(MainActivity.this, "",
                "Please wait....query task is executing");

    }


    @Override
    protected FeatureResult doInBackground(String... queryArray) {

        if (queryArray == null || queryArray.length <= 1)
            return null;

        String url = queryArray[0];
        QueryParameters qParameters = new QueryParameters();
        String whereClause = queryArray[1];
        SpatialReference sr = SpatialReference.create(102100);
        qParameters.setGeometry(map.getExtent());
        qParameters.setOutSpatialReference(sr);
        qParameters.setReturnGeometry(true);
        qParameters.setWhere(whereClause);

        QueryTask qTask = new QueryTask(url);

        try {
            FeatureResult results = qTask.execute(qParameters);

            return results;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    protected void onPostExecute(FeatureResult results) {

        String message = "No result comes back";

        if (results != null) {
            int size = (int) results.featureCount();
            for (Object element : results) {
                progress.incrementProgressBy(size / 100);
                if (element instanceof Feature) {
                    Feature feature = (Feature) element;

                    Graphic graphic = new Graphic(feature.getGeometry(),
                            feature.getSymbol(), feature.getAttributes());


                    graphicsLayer.addGraphic(graphic);

                    SimpleRenderer sr = new SimpleRenderer(new SimpleFillSymbol(Color.RED));
                    graphicsLayer.setRenderer(sr);
                     map.addLayer(graphicsLayer);


                }
            }

            message = String.valueOf(results.featureCount())
                    + " results have returned from query.";

        }
        progress.dismiss();
        Toast toast = Toast.makeText(MainActivity.this, message,
                Toast.LENGTH_LONG);
        toast.show();
        boolQuery = false;

    }

}
Tags (2)
0 Kudos
0 Replies