I have this json response from the server:
[
{
"id": 12767236,
"rowNumber": "01",
"seatNumber": 1,
"status": "taken"
},
{
"id": 12767237,
"rowNumber": "01",
"seatNumber": 2,
"status": "available"
}
...
...
...
]
Basically it's a list of seats with a few properties, that's all the data I have. So, question is how do I show the seats and let user pick one like below? What component should I use?
You can use GridLayoutManager but you have to have a dummy/empty item to represent those rows, but you will need logic to assign those specific items to the list
Related
Suppose I have the following JSON -
{
"list": [
{
"name": "John",
"age": 20
},
{
"name": "Peter"
"age": 18
},
{
"name": "Jane",
"age": 21
}
]
}
Is there a way in moshi in which we can skip the list item where the name is "Peter"?
My issue is that I need to show a list of items only if they match with certain values (eg. "imageType" = "jpeg") provided in json and skip everything else. I am wondering if one can do the skipping at the json parsing level rather than somewhere in the business logic where I would have to run a for loop and go through every element again.
I am trying to fetch JSON Object which has 2 list object with the same name, but has a different value. The object list named "items", the first "items" has "products_title,product_image,link", and the second "items" has "article_title, article_image,link". How to write PODO ?
I've been trying to writes PODO, but even i try to change the model, it still does not work. I try the other REST API, for the example "https://jsonplaceholder.typicode.com/pothos" its working fine. But if i try used my JSON its getting error, i wonder how to write PODO ?
this is the JSON i am using :
{
"data": [
{
"section": "electronics",
"items": [
{
"product_name": "Cellphone",
"product_image": "cellphoneImage.png",
"link": "https://cellphone.html"
},
]
},
{
"section": "facts",
"section_title": "Title section",
"items": [
{
"article_title": "Facts",
"article_image": "https://www.facts.png",
"link": "https://www.facts.html"
},
]
}
]
}
We are currently working on project where a web user creates a survey which has cascading questions (cascading means questions that have few answers and depend on those answers rest of the questions changes) and then mobile users should get this survey in their android app. Sample JSON structure we thought is as follows:
{
"status": "1",
"tabs": [
"Farmer Information",
"Signature",
"Crop Details",
"Land Parcel"
],
"survey":[
{
"type": "TextView",
"cascade": "0",
"value": "What is your name?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "What is your age?",
"survey" : ""
},
{
"type": "RadioButtonGroup",
"cascade": "1",
"value": "Do you have kids?",
"survey" : [
{
"type": "TextView",
"cascade": "1",
"value": "YES",
"survey": [
{
"type": "TextView",
"cascade": "1",
"value": "How many of them below 18?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "How many of them are girls?",
"survey" : ""
},
{
"type": "TextView",
"cascade": "1",
"value": "Where do you live in?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "How long you were there?",
"survey" : ""
}
]
},
{
"type": "TextView",
"cascade": "0",
"value": "NO",
"survey" : [
{
"type": "TextView",
"cascade": "1",
"value": "Where do you live in?",
"survey": ""
},
{
"type": "TextView",
"cascade": "0",
"value": "How long you were there?",
"survey" : ""
}
]
}
]
}
]
}
Is there anyway to achieve such a thing?
What are the most suitable library which can be used for this scenario? We tried json2view, proteus. From all those we can pass a json and load the view but if there are cascading questions non of them can use.
Furthermore elaborating in the question via an example:
Suppose the user is given the question of Do you have any have kids?. This question has possible two answers. Yes & No depending upon the answer which user give others questions have to be loaded dynamically.
This may be too late, but here goes. This can be done in proteus.
Philosophy: How would you do it in Native Android?
By creating a custom view, let call it SurveyView which has 3 custom attributes
status: initial condition
cascade: the check condition
survey: array of child SurveyView
So, in Native Android, there would be a method setStatus() which will be called when an answer is selected. This will set the status of the child survey views. The child will check the new status against the condition set on them. If it matches, it is visible else gone.
After this simply register this as a custom view with proteus. There is a slightly more complicated way of doing this without a custom view (by using function bindings in like so.
{
"visibility: "#{fn:eq(#{data.status}, 0)}"
}
Where data.status is the status propagated down from the parent and 0 is the cascade condition. You get the drift.
fn:eq is a built-in function. Check here for all available functions here
You can create and register your own custom functions too.
P.S. why not react native?
P.P.S Use proteus tag in questions related to proteus, this is why I missed this.
I am making use of Retrofit in my app, it manages API calls well and supports GET and PATCH as I require.
Given the following JSON:
"fruit_set": [
{
"id": 2,
"fruit": {
"id": 1,
"name": "Apple",
"desc": ""
},
"source": 2,
"inventory": 8.0
},
{
"id": 6,
"fruit": {
"id": 2,
"name": "Mango",
"desc": "delicious"
},
"source": 2,
"inventory": 15.0
}]
Ignoring names for a minute.
I have setup a PoJo for both FruitSet and Fruit with the required getters/setters. FruitSet.Fruit is defined as List and is populated nicely with a GET call. My problem is with PATCH.
Fruit in this instance is reference data therefore I only need to insert the Fruit.id when assigning it to my FruitSet PoJo.
Can I instruct Retrofit that it doesn't need to write Fruit but only the Fruit.id to the database table. I was hoping Retrofit was smart enough to do that?
Basically I want this JSON structure when I PATCH:
"fruit_set": [
{
"id": 2,
"fruit": 1,
"source": 2,
"inventory": 8.0
},
{
"id": 6,
"fruit": 2,
"source": 2,
"inventory": 15.0
}]
Any ideas?
For those looking I implemented a custom Gson serializer that outputs only the ID instead of the entire Fruit object. This article really helped, especially towards the bottom:
http://www.javacreed.com/gson-serialiser-example/
I have an url,get and response given. I have to parse the JSON and show the locations in Map in android. I dont need you to code. I am new in JSON. please tell me some steps how i can do that. how should i start and which steps i should take?
Url: "Some url"
Sending data:
{
"tag": "getAvailableDriver",
"lat": 41.022348,
"lng": -91.966721
}
RESPONSE:
{
"posts": [
{
"success": "1",
"driver": [
{
"id": "768",
"lat": "41.022848",
"lon": "-91.966884",
"recorded_datetime": "2014-07-20 20:18:03",
"user_id": "403",
"cabbi_state": "OnJob",
"vehicleType": "Black Cab",
"driver_name": "black cab driver",
"pic_name": "userimage/403.jpg",
"rating": "0",
"car_model": "this",
"number_sit": "4",
"distance": 0.035574527536789
}
],
"operator": [],
"nearestdistance": [
{
"distance": 0.03541809,
"time": 5
}
],
"car_models": [
"Taxi"
]
}
]
}
I just want anyone of you to guide me or show me the way. And also please someone tell me what will be the use of "send data" here. What is the use? I promise i will not ask any basic questions after i catch the grip. Help me please.
You can save the parsed data in an array, and for what I can see, there's a lot of tags in the JSON object. I suggest you to create an object of the type "Driver" or "Car", and then save all the data in that object. Once you have the data parsed and saved in an Array of the type of your object (Let's say an array of "Drivers" then you can use the info to add it into the Map.