Thursday, 28 August 2014

How to show Multiple Headings and Points in Single Activity



I am following this SO solution, and i have successfully parsed JSON, but don't know How to show both the headings and points in TextViews.


this is how my JSON looks:



{
"technology": [
{
"title": "Android",
"description": [
{
"heading": "Manufactures",
"points": [
"Google",
"Samsung"
]
},
{
"heading": "Platforms",
"points": [
"Kitkat",
"ICS"
]
}
]
}
]
}


For an example, if i do tap on Android, then i want to show something like this:



Manufactures
[dot] Google
[dot] Samsung

Platforms
[dot] Kitkat
[dot] ICS


For reference see this images:


enter image description here


In place of Why We Like It, i want to show Manufactures and in place of Need to Know, i want to show Platforms (with their respective points) as shown in Image.


But getting something like this:



Platforms
[dot] ICS


So what is the reason? and where i have to make changes in my code ?


DescriptionActivity.java:-



arrayListDescription = technology.getDescription();

for(int s=0; s<arrayListDescription.size(); s++)
{
description = arrayListDescription.get(s);
strHeading = description.getHeading();
Log.d("heading::", strHeading);
arrayListPoints = description.getPoints();

for(int z=0; z<arrayListPoints.size(); z++)
{
strPoints = "&emsp;&middot;" + arrayListPoints.get(z) + "\n";
Log.d("points::", strPoints);
}
textViewPoints.setText(Html.fromHtml(strPoints));
}

textViewHeading.setText(strHeading);
textViewHeading.setTextSize(24);

}


activity_description.xml:-



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/textHeading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

<TextView
android:id="@+id/textPoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>


this is what my Log says:



08-28 04:47:39.653: D/heading::(1902): Manufactures
08-28 04:47:39.653: D/points::(1902): &emsp;&middot;Google
08-28 04:47:39.671: D/points::(1902): &emsp;&middot;Samsung
08-28 04:47:39.761: D/heading::(1902): Platforms
08-28 04:47:39.761: D/points::(1902): &emsp;&middot;Kitkat
08-28 04:47:39.761: D/points::(1902): &emsp;&middot;ICS

No comments:

Post a Comment