我一直在推荐这个程序来制作一个画廊模块
https://github.com/nostra13/Android-Universal-Image-Loader

但是根据我的应用程序的要求,图像是动态添加的。所以,我通过JSON获取所有图像.JSON Iam的图像响应添加到arraylist中。

如何在新课程中传递“ image_urls.add(folio.getString(i));”:

public class Test extends Activity{

    private static String url = "http://www.xyz.com/album_pro/array_to_encode";

     JSONArray folio = null;
     ArrayList<String> urlList = new ArrayList<String>();
     @SuppressLint("NewApi")
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
              StrictMode.setThreadPolicy(policy);

            JSONParser jParser = new JSONParser();
            {

            try{

                JSONObject json = jParser.getJSONFromUrl(url);
                Log.v("URL",json.toString());

            JSONObject seo = json.getJSONObject("SEO");
            Log.v("seo",seo.toString());
            JSONArray folio = seo.getJSONArray("Folio");
            ArrayList<String> image_urls = new ArrayList<String>();

            for(int i=0;i< folio.length();i++)
            {

                image_urls.add(folio.getString(i));

            }


            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            }
}

}


如何在名为“ Images”的非活动类中传递“ image_urls.add(folio.getString(i));


public class Images {
    public final static String[] imageUrls = new String[] {
      **Required the arraylist of "Test" activity**

    };
    public final static String[] imageThumbUrls = new String[] {

         **Required the arraylist of "Test" activity**
    };

}

最佳答案

制作ArrayList publicstatic并在其他类中将其用作Test.urlList

07-24 09:45