dhamini poornachandra dhamini poornachandra - 3 months ago 7
Android Question

Dynamically load a list of images based on server response

I am sending a request to a server and the server sends a list of appliance names. I want to load images based on the appliance names returned by the server, right now the server has 200 types of appliance names, and the server returns a list of random appliance name each time I send a request. Is there an efficient way to load images based on the response server.
Any help is appreciated.
the response is as follows:

"appliance":

{
"id": 1,
"type": "electronic",
"make": "2015",
"model": "2011",
"serialNumber": "19218hdyew",
"serviceTagNumber": "hfh251663",
"name": "fridge"
},
{
"id": 2,
"type": "electronic",
"make": "2015",
"model": "2011",
"serialNumber": "19218hdyew",
"serviceTagNumber": "hfh251663",
"name": "coffee"
},
{
"id": 3,
"type": "electronic",
"make": "2015",
"model": "2011",
"serialNumber": "19218hdyew",
"serviceTagNumber": "hfh251663",
"name": "washing machine"
},
{
"id": 4,
"type": "electronic",
"make": "2015",
"model": "2011",
"serialNumber": "19218hdyew",
"serviceTagNumber": "hfh251663",
"name": "fan"
},
{
"id": 5,
"type": "electronic",
"make": "2015",
"model": "2011",
"serialNumber": "19218hdyew",
"serviceTagNumber": "hfh251663",
"name": "tv"
}

Answer

Your server is returning image names, then you should create a method like

displayimage(String imagename)

where imagename is string you are getting from server.

In displayimage method you can use setimageresource

Comments