I am new to SO, and although I’ve been through the FAQ’s, I hope I get this question right.
THE BACKGROUND
I have been successful in getting data using the Facebook SDK and displaying them in a custom listview. However, as any beginner, I have invariably slowed things down and the listview lags like crazy. To remedy that, I started implementing Lazy Loading using this example from SO: https://stackoverflow.com/a/3068012/450534
THE STUMBLING BLOCK
I this example @Fedor has hard-coded the URL’s into a String Array. Now I want to replace that String array with those fetched from the Facebook query result (JSON).
Also, is that a good example to follow (strictly for this scenario) or is there a better example out there? I have spent close to 2 days just trying to figure the lazy loading part out. But I am stumped either for lack of efficient searching or the fact that I’ve just begun.
I hope this question makes sense. Thank you for your advice.
Cheers….
A sample of the link to an image returned using JSON to parse a Facebook query.
04-23 01:44:28.505: V/PICTURE LINK URL :(3902): https://s-external.ak.fbcdn.net/safe_image.php?d=AQBZ5-jVGrHA2hpU&w=90&h=90&url=http%3A%2F%2Fblog.mozilla.org%2Ftheden%2Fwp-content%2Fthemes%2FTheDen%2Fimg%2Fbg-header.png
A subset of the way @Fedor has hard-coded the URL’s in his example.
private String[] mStrings={
"http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg",
"http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png",
"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",
"http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg",
"http://a1.twimg.com/profile_images/655119538/andbook.png",
"http://a3.twimg.com/profile_images/768060227/ap4u_normal.jpg",
"http://a1.twimg.com/profile_images/74724754/android_logo_normal.png",
"http://a3.twimg.com/profile_images/681537837/SmallAvatarx150_normal.png"
};
EDIT
The new edit was going to take a lot of space. Therefore, I am linking it pastebin: http://pastebin.com/HZfCTMy6
The facebook API has a bug where if there is a shared post on the News Feed, it does not give a “picture” tag and another query has to be made to get the picture URL using the “object_id” tag. In the pastebin code, this is put in an if + else if code block starting at line number 155
This is really a lengthy piece of code and I appreciated the time you may take going through it.
Any help with this will be really, really appreciated. Over two days and no solution in sight. 🙁
If you have a hardcoded definition like that:
you can simply break it with adding a setter (and changing for String array to a dynamic collection):
If there’s code in the constructor that depends on the array to have values, then move it to a new method and call it after you finished adding the strings.
As for the format of the data from facebook, since they return json it’s easy to get the exact data you need, just extract the needed urls and add them to the list.
Edit
This is from your code:
This of course will result in having just one url in the listOfUrls, you construct a new ArrayList every time, you should not do that.
It should look something like: