android - Insert imagepath dynamically -


i'm trying images in grid view using universalimageloader github. instead of loading static final image constant, want load image path dynamically server. made jsonparser load information server , parse it. i'm struggling assign images string array. please suggest me how assign. i'm newbie android.

imageconstants.java

import java.util.arraylist; import java.util.hashmap;  import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject;  import android.app.progressdialog; import android.os.asynctask; import android.util.log;  public class imageconstant {      public static string[] image1;     private static string[] constants;     public static string url = "http://ensign119.com/assets/image11.php";          // json node names         protected static final string tag_products = "image_path";         protected static final string tag_cid = "file_id";         public static final string tag_name = "file_name";          // contacts jsonarray           jsonarray products = null;      public string[] imageconstant() {         // todo auto-generated constructor stub          new message().execute(url);         for(int i=0; i<image1.length;i++){             constants[i] = image1[i];         }          for(string name:constants){             log.d("new path", name);         }          return constants;     }      class message extends asynctask<string, integer, arraylist<hashmap<string, string>> > {         arraylist<hashmap<string, string>> mylist = new arraylist<hashmap<string, string>>(); //      progressdialog progress = new progressdialog(path.this);         // creating json parser instance         jsonparser jparser = new jsonparser();                 @override             protected arraylist<hashmap<string, string>> doinbackground(string... params) {                      log.d("doinbackgound","backgound running");                      log.d("json string ", jparser.getjsonfromurl(url).tostring());                     // getting json string url                     jsonobject json = jparser.getjsonfromurl(url);                      log.d("path_parsing", "before parsing");                     try {                         // getting array of contacts                         products = json.getjsonarray(tag_products);                          // looping through contacts                         for(int = products.length()-1; >=0; i--){                             jsonobject c = products.getjsonobject(i);                              // storing each json item in variable                             string cid = c.getstring(tag_cid).tostring();                             string name = c.getstring(tag_name);                             // creating new hashmap                             hashmap<string, string> map = new hashmap<string, string>();                              // adding each child node hashmap key => value                             map.put(tag_cid, cid);                             map.put(tag_name, name);                              // adding hashlist arraylist                             mylist.add(map);                             log.d("mylist_value", mylist.tostring());                         }                     } catch (jsonexception e) {                         e.printstacktrace();                     }                     log.d("path_parsing", "after parsing");                        return mylist;                  }              @override             protected void onpostexecute(arraylist<hashmap<string, string>> result) { //              if(progress.isshowing()){ //                  progress.dismiss(); //              }                 image1 = new string[result.size()];                 for(int i=0; i<result.size(); i++){                    image1[i] = result.get(i).get("file_name");                 }                 for(string path: image1){                     log.d("path", path.tostring());                 }                 log.d("postexecute","postexecute running");             }              @override             protected void onprogressupdate(integer... values) {                 // todo auto-generated method stub                 super.onprogressupdate(values);              }              @override             protected void onpreexecute() {                 // todo auto-generated method stub             }     }  } 

constants.java

public final class constants {      public static final string[] images = new string[] {              "http://wrong.site.com/corruptedlink", // wrong link     };      private constants() {     }      public static class config {         public static final boolean developer_mode = false;     }      public static class {         public static final string images = "com.nostra13.example.universalimageloader.images";         public static final string image_position = "com.nostra13.example.universalimageloader.image_position";     } } 

try this, 

https://github.com/thest1/lazylist

in gridview adapter, add code in getview() method  imageloader imageloader = new imageloader(mainactivity.this); imgloader.displayimage(your image path, imageview); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -