Support Topics Documentation Slack YouTube Blog

How to get this list


(Tpg Third) #1

Hi I need help with retrieving relations, if this method returns this list to my android project, How can I retrieve this list to use in a listView?

loadTeamsPlayer a = loadTeamsPlayer.getInstance().getInstance().getInstance().getInstance();
a.playersListAsync(teamId, new AsyncCallback() {
@Override
public void handleResponse(Object response)
{
//Should get and use the list here
}

                                @Override
                                public void handleFault(BackendlessFault fault)
                                {
                                    Toast.makeText(getBaseContext(), fault.getMessage(), Toast.LENGTH_LONG).show();
                                }
                            });

and also I am not sure what I should put in this part (<List<Map<String, Object).

Backendless.Data.of( PARENT-CLASS ).loadRelations(

LoadRelationsQueryBuilder<List<Map<String, Object>>> queryBuilder,

AsyncCallback<List<CHILD-CLASS>> callback );

Thank You


(Mark Piller) #2

I assume you’re talking about the Android ListView. To populate it with data you need to use an Adapter, in this case the ArrayAdapter would work. First of all, make sure your codeless method returns an array of objects. This can be done with Backendless Console.

As for your second question, the part you referenced is a generic type, it indicates that the response will be a list of map objects. Each map object contains key (string) / value (object) pairs

Hope this helps.

Mark


(Tpg Third) #3

This is what my response is, it is the data that I want , but my question is how do I get this in my android project as an arraylist or list of players.

[
[
{
“___jsonclass”: “players”,
“allergies”: “none”,
“parentNumber1”: “none”,
“parentNumber2”: “none”,
“created”: 1536692206390,
“team”: “qwe”,
“ownerId”: “9177942B-AC09-ED44-FF1F-90AEDFF86300”,
“medAidNumber”: “none”,
“serialVersionUID”: -6756968448316414000,
“surname”: “a”,
“name”: “a”,
“___class”: “players”,
“medAidName”: “none”,
“medAidPlan”: “none”,
“updated”: null,
“objectId”: “3AA2008C-34CC-1052-FF0D-26F7AA201000”
},
{
“___jsonclass”: “players”,
“allergies”: “none”,
“parentNumber1”: “none”,
“parentNumber2”: “none”,
“created”: 1536692266854,
“team”: “qwe”,
“ownerId”: “9177942B-AC09-ED44-FF1F-90AEDFF86300”,
“medAidNumber”: “none”,
“serialVersionUID”: null,
“surname”: “f”,
“name”: “f”,
“___class”: “players”,
“medAidName”: “none”,
“medAidPlan”: “none”,
“updated”: null,
“objectId”: “B8579FD7-4D80-99BE-FF7F-063A7B8A7B00”
},
{
“___jsonclass”: “players”,
“allergies”: “none”,
“parentNumber1”: “none”,
“parentNumber2”: “none”,
“created”: 1536693242981,
“team”: “qwe”,
“ownerId”: “9177942B-AC09-ED44-FF1F-90AEDFF86300”,
“medAidNumber”: “none”,
“serialVersionUID”: -6756968448316414000,
“surname”: “awee”,
“name”: “aweeee”,
“___class”: “players”,
“medAidName”: “none”,
“medAidPlan”: “none”,
“updated”: null,
“objectId”: “CA4509A8-127A-9347-FF51-B438301D0100”
}
]
]


(Sergey Chupov) #4

In your current setup you are receiving a JSON object from your Codeless service method. This means you have to parse it and map to the objects in your code.

But it can be tedious to do, moreover I’ve looked into the implementation of your codeless method and it seems to me that you can replace it with a single query in your Android app code:

LoadRelationsQueryBuilder<Map<String, Object>> query = LoadRelationsQueryBuilder.ofMap();
query.setRelationName( "RTP" );
query.setPageSize( 100 );
Backendless.Data.of( "teams" ).loadRelations( teamId, query, new AsyncCallback<List<Map<String,Object>>>()  {
    @Override
    public void handleResponse( List<Map<String, Object>> rtpObjects ) {
        // here you can process the rtpObjects response object
    }

    @Override
    public void handleFault( BackendlessFault fault )
    {
        Toast.makeText( getBaseContext(), fault.getMessage(), Toast.LENGTH_LONG ).show();
    }
}

If anything is not totally clear, please refer to the relevant documentation part: http://backendless.com/docs/android/doc.html#data_two_step_retrieval