Jump to content









Photo

Get at_ and display it to the user in android

at_ android

  • Please log in to reply
1 reply to this topic

#1 eric3231559

eric3231559

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts

Posted 22 July 2014 - 08:33 AM

Hi there, may i know how can i get the at_ with the temperature value and display it to the user. 

 

I wanna get a list which able to display left is the date and time while right display the temperature value.

 

FOr the time being i able to get the json data from the carriots and parse the temperature value and display it on a list in my android phone. 

 

 

 



#2 rebeburns

rebeburns

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 22 July 2014 - 11:56 AM

Hello,

 

To display the date on the left and the temperature on the right you might want to use a table. You can see how to here:

 

http://stackoverflow...ultiple-columns

 

If you specify the number of streams you want to receive from Carriots you can make the table in the xml layout file. Otherwise, since you don't know the number of streams you would have to make add rows to the table dynamically. I suggest you try making a static table first(ask for a max=10 in the url for example and then put 10 rows in your table in the xml layout file).

 

To get the "at" value the process is very similar to what you do to parse the temperature. This example below is from GitHub (https://github.com/c...SendStream.java) and it finds the "at" value and all the "data" from that time.

 

JSONArray res=nodeRoot.getJSONArray("result");
//go through the array and get the values of the time "at" and data "data"
int i=0;
int previousSize=atList.size();
do{
JSONObject childJSON = res.getJSONObject(i);
if (childJSON.get("at")!=null){
String value = childJSON.getString("at");
//if the data has already been sent once use the set method instead of add
if (sent!=1){
atList.add(value);
}else{
if(previousSize==i){
atList.add(value);
}else{
atList.set(i, value);
}
}
}
if (childJSON.get("data")!=null){
String value = childJSON.getString("data");
//if the data has already been sent once use the set method instead of add
if (sent!=1){
dataList.add(value);
}else{
if(previousSize==i){
dataList.add(value);
}else{
dataList.set(i, value);
}
}
}
i++;
}while(i<res.length() && i<10);
 
I hope looking at the example will give you an idea of how to access the at value.






Also tagged with one or more of these keywords: at_, android

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users