Skip to content Skip to sidebar Skip to footer

Android Lazy Loading Images From JSON Into Gridview

So i am trying to load images from my returned json array into a staggered gridview. I have already tested putting links directly into the array like the example and it works perfe

Solution 1:

 StaggeredAdapter adapter = new StaggeredAdapter(MainActivity.this,
                R.id.imageView1, urls);

        gridView.setAdapter(adapter);
        adapter.notifyDataSetChanged();

add this above code in onPostExecute in AsyncTask

Hope this will help you.


Solution 2:

This line 03-22 14:57:59.286: E/AndroidRuntime(1183): at com.example.staggeredgridviewdemo.MainActivity.onCreate(MainActivity.java:89) says there is some problem in line 89 of your MainActivity. This is where you create the adapter. If you look closely, you'll see that you try to create the adapter with a null list of items - urls is not initialized yet.

The AsyncTask you use is executed in a different thread, so everything that happens in doInBackground (like urls = new String[jarray.length()];) is in another thread. Which, in this case, means that the urls array is initialized after it is used to create the adapter.

To avoid this you can initialize the array before you start the activity. If you don't know it's size at this moment, you can use another adapter, like ListAdapter to initialize it with a non-null list and then fill this list from the activity and call notifyDataSetChanged after the task has finished.


Solution 3:

Check the data feed, http://snapoodle.com/APIS/android/feed.php , I do not see any data returned from the request.

{"print":[]}


Solution 4:

I was a bit dumb, but I solved it by moving my staggered grid view to onPostExecute and returning urls from do in background


Post a Comment for "Android Lazy Loading Images From JSON Into Gridview"