Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android使用JSON url加载列表中的图像_Android_Json_Image_Tumblr - Fatal编程技术网

Android使用JSON url加载列表中的图像

Android使用JSON url加载列表中的图像,android,json,image,tumblr,Android,Json,Image,Tumblr,我目前有一段带有purl.getString(“url”)的代码,其中包含指向jpg在线图像的url链接。我想在列表或网格中显示这些图像,但无法理解如何显示。当前代码只是列出listview中的所有URL,但只希望这些URL是它们各自的图像 这是我的密码 public class BreadActivity extends ListActivity { /** Called when the activity is first created. */ @Override public void

我目前有一段带有purl.getString(“url”)的代码,其中包含指向jpg在线图像的url链接。我想在列表或网格中显示这些图像,但无法理解如何显示。当前代码只是列出listview中的所有URL,但只希望这些URL是它们各自的图像

这是我的密码

public class BreadActivity extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, this.fetchJsonStuff()));
       }

public ArrayList<String> fetchJsonStuff()
{
    ArrayList<String> listItems = new ArrayList<String>();
    try {
        URL example = new URL(
                "http://api.tumblr.com/v2/blog/example.tumblr.com");
        URLConnection tc = example.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));

        String line;
        while ((line = in.readLine()) != null) {
            JSONObject ob = new JSONObject(line);
            JSONObject object = ob.getJSONObject("response");
            JSONArray ja = object.getJSONArray("posts");

            for (int i = 0; i < ja.length(); i++) {
                JSONObject jo = (JSONObject) ja.get(i);
                JSONArray nja = (JSONArray) jo.getJSONArray("photos");

            for (int i1 = 0; i1 < nja.length(); i1++) {
                JSONObject njo = (JSONObject) nja.get(i1);
                JSONObject purl = (JSONObject) njo.getJSONObject("original_size");
                listItems.add(purl.getString("url"));

            }

            }
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return listItems;
}

  }
公共类BreadActivity扩展了ListActivity{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setListAdapter(新的ArrayAdapter(this,android.R.layout.simple_list_item_1,this.fetchjsonstaff());
}
公共ArrayList fetchjsonstaff()
{
ArrayList listItems=新的ArrayList();
试一试{
URL示例=新URL(
"http://api.tumblr.com/v2/blog/example.tumblr.com");
URLConnection tc=example.openConnection();
BufferedReader in=新的BufferedReader(新的InputStreamReader(
tc.getInputStream());
弦线;
而((line=in.readLine())!=null){
JSONObject ob=新的JSONObject(行);
JSONObject object=ob.getJSONObject(“响应”);
JSONArray ja=object.getJSONArray(“posts”);
对于(int i=0;i
能否提供结果字符串???能否提供结果字符串???