I published a points-layer as a runtime content (Cities layer, its table include a field for cities’ names: “[Name]”), how can I query features (Cities points) using their names which the user types in a text box (EditText)?
Please check out the sample:
Query Feature Service Table | ArcGIS for Developers
However, this sample is a query on GeodatabaseFeatureServiceTable. Since you mentioned that you published a points-layer as a runtime content, it should be GeodatabaseFeatureTable instead.
The difference between GeodatabaseFeatureServiceTable and GeodatabaseFeatureTable is:
In a connected workflow, the type of feature table you create and edit is a GeodatabaseFeatureServiceTable. In a disconnected workflow, the type of feature table you create and edit is a GeodatabaseFeatureTable. The class hierarchy between these is GeodatabaseFeatureServiceTable is inherited from GeodatabaseFeatureTable.
Now let's go over the code:
In onClick_okButton method:
// Create query parameters, based on the constructed where clause.
QueryParameters queryParams = new QueryParameters(); queryParams.setWhere(whereClause);
// Execute the query and create a callback for dealing with the results of the query. featureServiceTable.queryFeatures(queryParams, new CallbackListener<FeatureResult>() { @Override public void onError(Throwable ex)
{ // Highlight errors to the user.
showToast("Error querying FeatureServiceTable"); }
@Override public void onCallback(FeatureResult objs)
{ // If there are no query results, inform user.
if (objs.featureCount() < 1) { showToast("No results"); return; }
// Report number of results to user.
showToast("Found " + objs.featureCount() + " features.");
// Iterate the results and select each feature.
for (Object objFeature : objs) { Feature feature = (Feature) objFeature; featureLayer.selectFeature(feature.getId()); } } }); }
Note that featureServiceTable.queryFeatures, you can change it to GeodatabaseFeatureTable.queryFeatures, and set up the parameters in QueryParameters.
See the API reference for the detailed information:
GeodatabaseFeatureTable | ArcGIS Android 10.2.4 API
Let me know if you have any questions.
Dear Mengyi,
Thank you very much for your massive contribution, I tried this code, and it worked well!
Thank you again and Best Regards,
Hani
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.