Follow/unFollow button on a lsitView populated by a request to a REST Webservice

Asked

Viewed 33 times

0

So guys, my question is this::

I have a ListView which is popular for a request to my web service REST. Each item of this ListView has a button. By clicking this button, the user logged into the app will be able to "follow" or "stop following" the entity represented in the item (something very similar to what happens when you "follow" an Instagram profile, for example).

My question is, how to maintain the status of the button on ListView (If the user is following, write "following", if not write "following"). Would the best way would be for me to already submit whether or not the user follows that entity in the request to the web service that fills the list, manipulating the returned JSON?

I accept suggestions =)

1 answer

1

I see no problem in already sending in the answer of the webservice the status "following" of each item (true or false, 1 or 0, or as you prefer). You see a problem with this?

When the user touches the button of an item ("Follow" or "Stop following"), it is up to you to decide how to implement the status change. For simplicity you can make a web service that makes toggle state, that is, it switches from one state to another regardless of the initial state. It is called, checks on the server which is the current state and changes that state, returning the new state so you can update your view.

Or you make a more demanding web service in relation to the consistency of the data: it receives the current state (true or false), validates on the server if the state is the same, changes the state, and returns the new state, otherwise returns error (HTTP 400 - Bad Request, for example).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.