Hi i am having trouble to get the JSONObject value title and store into the array.
public class ViewPagerAdapter extends PagerAdapter
{
// JSON Node names
private static final String TAG_CATEGORIESLIST = "categorylist";
private static final String TAG_TITLE = "title";
private static final String TAG_URL = "url";
public static String[] titles;
public final Context context;
public int[] scrollPosition;
JSONArray categories = null;
JSONObject json;
{
try {
JSONFunction JSONFunction = new JSONFunction();
json = JSONFunction.categorylist();
// Getting Array of Categories
categories = json.getJSONArray(TAG_CATEGORIESLIST);
// looping through All Categories
for(int i = 0; i < categories.length(); i++){
JSONObject c = categories.getJSONObject(i);
// Storing each json item in variable
String title = c.getString(TAG_TITLE);
String url = c.getString(TAG_URL);
titles = new String[] {title}; //only obtain one result
scrollPosition = new int[titles.length];
}
} catch (JSONException e) {
e.printStackTrace();
}
}
...
My titles only get one value, need some help from u guys.
Addon:
I am using Viewpagerindicator library, the default code to display the title is like tat
private static String[] titles = new String[] { “Page 1”, “Page 2”,
“Page 3”, “Page 4”, “Page 5”};
I am trying to input json data into there.
Thanks.
you are not incrementing the titles array
Change this
to