androidsortingandroid-studiobuttonbackendless

How do I sort Data from backendless and Hide (Not Remove) Duplicates for Android?


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() );
                                }} );

Solution

  • 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() ); 
      }
    });