0
I’m new to Android development, and I’m trying for days to make my first app work but without success. I am using Asynctask to make the request and Simpleadapter, it back the data but my JSON has sub-items. It is a JSON of comments where sometimes in a comment has the answers of that comment. But I have no idea if I make a listview inside a listview or nda. I’m really lost, I researched a lot and nothing.
Follows the JSON:
{
COMENTARIOS: [
{
comentarios_id: "1053939",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "0",
videos_id: "0",
nome: "ludi",
email: "[email protected]",
ip: "186.212.2.226",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 09:34:00",
status: "3",
gostei: "67",
naogostei: "143",
resp: [ ]
},
{
comentarios_id: "1053943",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "0",
videos_id: "0",
nome: "Andre",
email: "[email protected]",
ip: "187.120.224.30",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 09:45:01",
status: "3",
gostei: "236",
naogostei: "114",
resp: [
{
comentarios_id: "1053945",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "1053943",
videos_id: "0",
nome: "Usuário",
email: "[email protected]",
ip: "187.39.180.166",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 09:51:54",
status: "3",
gostei: "143",
naogostei: "219",
resp: [ ]
},
{
comentarios_id: "1053987",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "1053943",
videos_id: "0",
nome: "Roberto, o Legítimo",
email: "[email protected]",
ip: "177.6.152.156",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 11:39:52",
status: "3",
gostei: "82",
naogostei: "124",
resp: [ ]
},
{
comentarios_id: "1054030",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "1053943",
videos_id: "0",
nome: "xumbinho",
email: "[email protected]",
ip: "186.232.178.237",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 13:19:51",
status: "3",
gostei: "69",
naogostei: "116",
resp: [ ]
}
]
},
{
comentarios_id: "1053964",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "0",
videos_id: "0",
nome: "Celso",
email: "[email protected]",
ip: "177.97.174.169",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 10:38:06",
status: "3",
gostei: "41",
naogostei: "116",
resp: [ ]
},
{
comentarios_id: "1054061",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "0",
videos_id: "0",
nome: "Usuário",
email: "[email protected]",
ip: "181.223.181.27",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 14:23:10",
status: "3",
gostei: "60",
naogostei: "15",
resp: [
{
comentarios_id: "1054173",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "1054061",
videos_id: "0",
nome: "bob",
email: "[email protected]",
ip: "92.59.121.38",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 17:19:32",
status: "3",
gostei: "5",
naogostei: "106",
resp: [ ]
},
{
comentarios_id: "1054485",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "1054061",
videos_id: "0",
nome: "Usuário",
email: "[email protected]",
ip: "187.55.120.227",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-04 10:24:56",
status: "3",
gostei: "0",
naogostei: "0",
resp: [ ]
}
]
},
{
comentarios_id: "1054304",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "0",
videos_id: "0",
nome: "Jorge",
email: "[email protected]",
ip: "189.74.113.127",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 21:00:03",
status: "3",
gostei: "1",
naogostei: "0",
resp: [ ]
},
{
comentarios_id: "1054382",
noticias_id: "284901",
duelos_id: "0",
respostas_id: "0",
videos_id: "0",
nome: "Pé na cova",
email: "[email protected]",
ip: "168.194.160.137",
comentario: "COMENTÁRIO",
data_cadastro: "2018-04-03 23:45:29",
status: "3",
gostei: "1",
naogostei: "0",
resp: [ ]
}
]
}
No Asynctask in function protected Void doInBackground(Void... arg0)
I make the JSON call that way:
JSONArray comentarios = jsonObj.getJSONArray("COMENTARIOS");
for (int i = 0; i < comentarios.length(); i++) {
JSONObject c = comentarios.getJSONObject(i);
String nome = c.getString("nome");
String comentario = c.getString("comentario");
HashMap<String, String> comentariotxt = new HashMap<>();
comentariotxt.put("nome", nome);
comentariotxt.put("comentario", comentario);
JSONArray resp = c.getJSONArray("resp");
if(resp.length() > 0){
for (int j = 0; j < resp.length(); j++){
JSONObject d = resp.getJSONObject(j);
String respostaNome = d.getString("nome");
String respostaComentario = d.getString("comentario");
Log.d("respostaNome",respostaNome);
HashMap<String, String> respostatxt = new HashMap<>();
respostatxt.put("respostaNome", respostaNome);
respostatxt.put("respostaComentario", respostaComentario);
comentarioList.add(respostatxt);
}
}
comentarioList.add(comentariotxt);
}
But here it already messes up everything. Because I need two things. Let them bring the commentary and the answers in order and the appearance of the response balloon will be different from the balloon of the commentary. At the moment I’m just making a listview of the comments, but I also don’t know if I need another listview for the answers. That is.. I am very lost! Someone help me?
Thank you very much, guys!
Explain more. I can’t understand what you need
– Icaro
Hello Icaro! All right? My question is that I do not know how to pass this information to Layout! Because the listview I made is only of the comments. So how would the response of each comment be displayed below the comment? If I have to change something or can follow more or less like I did
- comentário
 --- resposta
 --- resposta
 --- resposta
-comentário
-comentário
 --- resposta
 --- resposta
comentário
...
For example this. Thank you very much!– user2950020