Support Topics Documentation Slack YouTube Blog

Add geo categories to array

Hello,

I’m trying to add all geo categories to an array via the api and have them all displayed in a drop down menu for the user to select the category. This is what I have so far, am I even remotely close?

Backendless.Geo.getCategories(new AsyncCallback<List>() {
@Override
public void handleResponse( List geoCategories )
{
private List categoriesNames = new ArrayList();
List categories = geoCategories;
for( GeoCategory category : categories ) categoriesNames.add( category.getName() );

                spinner = findViewById(R.id.spinner1);
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);
                spinner.setAdapter(adapter);
            }

            @Override
            public void handleFault( BackendlessFault backendlessFault )
            {

            }
        });

Hello

here is doc for retrieving Geo Categories https://backendless.com/docs/android/geo_retrieving_geo_categories.html

Regards, Vlad

I am an total n00b and the examples are very clear because of that. The issue I seem to be having is getting the category into an array and getting that array to display its contents in spinner1. Any help would be greatly appreciated.

Backendless.Geo.getCategories(new AsyncCallback<List<GeoCategory>>() {
                    @Override
                    public void handleResponse( List<GeoCategory> category )
                    {
                        ArrayList<String> spinnerArray = new ArrayList<>();

                        Spinner spinner =  findViewById(R.id.spinner1);
                        // Create an ArrayAdapter using the string array and a default spinner layout
                        ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>
                                **(this, android.R.layout.simple_spinner_item, spinnerArray);**
                        // Specify the layout to use when the list of choices appears
                        spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        // Apply the adapter to the spinner
                        spinner.setAdapter(spinnerArrayAdapter);
                    }
                    @Override
                    public void handleFault( BackendlessFault backendlessFault )
                    {

                    }
                });

Ho Rodney,

This is more of a UI type of question and is not related to Backendless APIs. Try posting it to StackOverflow, I am sure you will get a response very quickly.

Regards,
Mark