Advertisement
Guest User

How to Show online Images instead of Local Drawables

a guest
Aug 27th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. JSON:-
  2. -------
  3.  
  4. {
  5. "technology" : [
  6. {
  7. "title" : "Android",
  8. "images" : [
  9. "http://www.mobiles24.com/static/previews/downloads/default/160/P-591219-73M4pzwvrf-1.jpg",
  10. "http://www.mobiles24.com/static/previews/downloads/default/160/P-591218-lm8TkZmOUl-1.jpg",
  11. "http://www.mobiles24.com/static/previews/downloads/default/160/P-591211-SJSiDbj8g4-1.jpg"
  12. ]
  13. },
  14. {
  15. "title" : "Google TV",
  16. "images" : [
  17. "http://www.mobiles24.com/static/previews/downloads/default/160/P-591206-vWt1VyROtB-1.jpg",
  18. "http://www.mobiles24.com/static/previews/downloads/default/160/P-591210-8SmWeokHYu-1.jpg",
  19. "http://www.mobiles24.com/static/previews/downloads/default/160/P-591209-l31zqQi9FG-1.jpg"
  20. ]
  21. }
  22. ]
  23. }
  24.  
  25. ImagesActivity.java:-
  26. -----------------------
  27.  
  28. public class ImagesActivity extends Activity {
  29.  
  30. private ViewFlow viewFlow;
  31.  
  32. /** Called when the activity is first created. */
  33. @Override
  34. public void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36.  
  37. setContentView(R.layout.screen_layout);
  38.  
  39. Bundle bund = getIntent().getExtras();
  40.  
  41. int i = bund.getInt("dataPosition");
  42. Log.d("position:", String.valueOf(i));
  43.  
  44. String strTitle = bund.getString("title");
  45. Log.d("title:", strTitle);
  46.  
  47. bund.getSerializable("images");
  48.  
  49. viewFlow = (ViewFlow) findViewById(R.id.viewflow);
  50. viewFlow.setAdapter(new ImageAdapter(this), 0);
  51.  
  52. CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic);
  53. viewFlow.setFlowIndicator(indic);
  54. }
  55.  
  56. ImageAdapter.java:-
  57. ---------------------
  58.  
  59. public class ImageAdapter extends BaseAdapter {
  60.  
  61. LayoutInflater layoutInflater;
  62. ViewHolder viewHolder;
  63.  
  64. private static final int[] ids = {
  65. R.drawable.a_1,
  66. R.drawable.a_2,
  67. R.drawable.a_1,
  68. R.drawable.a_2,
  69. R.drawable.a_1
  70. };
  71.  
  72. public ImageAdapter(Context context) {
  73. layoutInflater = (LayoutInflater) context
  74. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  75. }
  76.  
  77. @Override
  78. public int getCount() {
  79. return ids.length;
  80. }
  81.  
  82. @Override
  83. public Object getItem(int position) {
  84. return position;
  85. }
  86.  
  87. @Override
  88. public long getItemId(int position) {
  89. return position;
  90. }
  91.  
  92. @Override
  93. public View getView(int position, View convertView, ViewGroup parent) {
  94.  
  95. View view = convertView;
  96. if (view == null) {
  97. viewHolder = new ViewHolder();
  98. view = layoutInflater.inflate(R.layout.image_item, null);
  99. viewHolder.imageview = (ImageView) view.findViewById(R.id.imgView);
  100.  
  101. view.setTag(viewHolder);
  102.  
  103. } else {
  104.  
  105. viewHolder = (ViewHolder) view.getTag();
  106. }
  107. viewHolder.imageview.setImageResource(ids[position]);
  108.  
  109. return view;
  110. }
  111.  
  112. static class ViewHolder {
  113. public ImageView imageview;
  114. }
  115.  
  116. /*
  117. // class to download images
  118. private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
  119. ImageView bmImage;
  120.  
  121. public DownloadImageTask(ImageView bmImage) {
  122. this.bmImage = bmImage;
  123. }
  124.  
  125. protected Bitmap doInBackground(String... urls) {
  126. String urldisplay = urls[0];
  127. Bitmap mIcon11 = null;
  128. try {
  129. InputStream in = new java.net.URL(urldisplay).openStream();
  130. mIcon11 = BitmapFactory.decodeStream(in);
  131. } catch (Exception e) {
  132. Log.e("Error", e.getMessage());
  133. e.printStackTrace();
  134. }
  135. return mIcon11;
  136. }
  137.  
  138. protected void onPostExecute(Bitmap result) {
  139. bmImage.setImageBitmap(result);
  140. }
  141.  
  142. }
  143. */
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement