Advertisement
Guest User

Untitled

a guest
May 31st, 2014
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package com.example.staggeredgridviewdemo;
  2.  
  3. import org.json.JSONArray;
  4. import org.json.JSONException;
  5. import org.json.JSONObject;
  6.  
  7. import android.app.Activity;
  8. import android.os.AsyncTask;
  9. import android.os.Bundle;
  10. import android.view.Menu;
  11.  
  12. import com.origamilabs.library.views.StaggeredGridView;
  13.  
  14. public class MainActivity extends Activity {
  15.  
  16. private String urls[];
  17. String location = "http://snapoodle.com/APIS/android/feed.php";
  18. static final String TAG_ITEMS = "print";
  19. StaggeredGridView gridView;
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. new getImages().execute();
  26. gridView = (StaggeredGridView) this
  27. .findViewById(R.id.staggeredGridView1);
  28.  
  29. }
  30.  
  31. class getImages extends AsyncTask<String, Void, String> {
  32.  
  33. @Override
  34. protected String doInBackground(String... params) {
  35. // TODO Auto-generated method stub
  36. JSONObject json = JSONfunctions.getJSONfromURL(location);
  37.  
  38. try {
  39. JSONArray jarray;
  40. jarray = json.getJSONArray(TAG_ITEMS);
  41. urls = new String[jarray.length()];
  42.  
  43. for (int i = 0; i < jarray.length(); i++) {
  44. JSONObject gridImages = jarray.getJSONObject(i);
  45. urls[i] = gridImages.getString("saved_location");
  46. }
  47.  
  48. } catch (JSONException e) {
  49. // TODO Auto-generated catch block
  50. e.printStackTrace();
  51. }
  52.  
  53. return null;
  54. }
  55.  
  56. @Override
  57. protected void onPostExecute(String result) {
  58. // TODO Auto-generated method stub
  59. super.onPostExecute(result);
  60. StaggeredAdapter adapter = new StaggeredAdapter(MainActivity.this,
  61. R.id.imageView1, urls);
  62.  
  63. gridView.setAdapter(adapter);
  64. adapter.notifyDataSetChanged();
  65. }
  66. }
  67.  
  68. @Override
  69. public boolean onCreateOptionsMenu(Menu menu) {
  70. getMenuInflater().inflate(R.menu.activity_main, menu);
  71. return true;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement