2

I am Creating An App that will allow users to select Drinks From a tablet with in the store. The Store Managers will be able to upload New Drinks from Backendless. The Goal is to have a button For Every Brand however I am unsure of how to stop from Duplicating a button For two Different Drinks. How My Table Is set up

Originally I was going to Attempt to sort them then Count them but then add the buttons to match but I do not know how have it only Count the Brand Once. I searched Through Backendless's API Documentation and I was unable to find what I needed.

     DataQueryBuilder queryBuilder = DataQueryBuilder.create();


          Backendless.Data.of( "Location_1" ).getObjectCount( queryBuilder,
                    new AsyncCallback<Integer>()
                    {
                     @Override
                 public void handleResponse( Integer integer )
                                {
                         Log.i( "MYAPP", "found Brands " + integer );

    }
     @Override
     public void handleFault( BackendlessFault backendlessFault )
                                {
   Log.i( "MYAPP", "error - " + backendlessFault.getMessage() );
                                }} );
Jarrod Barfield
  • 105
  • 1
  • 7

1 Answers1

4

You should use the COUNT aggregate function and group the results by the Brand name. The API is described in the doc at: https://backendless.com/docs/android/doc.html#data_count

Here's a sample code:

DataQueryBuilder dataQueryBuilder = DataQueryBuilder.create();
dataQueryBuilder.setProperties( "Count(objectId)", "Brand" );
dataQueryBuilder.setGroupBy( "Brand" );
Backendless.Data.of( "Brands" ).find( dataQueryBuilder, new AsyncCallback<List<Map>>()
{
  @Override
  public void handleResponse( List<Map> response )
  {
    Log.i( "MYAPP", response );
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
    Log.e( "MYAPP", fault.toString() ); 
  }
});
Mark Piller
  • 1,046
  • 1
  • 7
  • 6
  • 1
    How would I then Display the brand as Button? Everything that I tried comes up as NULL – Jarrod Barfield Sep 26 '18 at 19:04
  • 2
    That would be more of an Android UI question (which is not my forte). Try posting it to an Android discussion group and to make it easier to understand say that you get a collection of objects from the server, where each object is represented by java.util.Map. Then describe the issue of creating buttons from one of the properties in the received maps. – Mark Piller Sep 27 '18 at 06:35