得到一个URL动态地的形象 [英] get a image of a url dynamicly

查看:108
本文介绍了得到一个URL动态地的形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview\">Android - 如何做的ListView图像的延迟加载

我尝试做什么

大家好,我只是建造了应用程序为我的YouTube的频道。为此,我使用JSON来获取信息并传递到我的ListView超过SimpleListAdapter。

Hello everyone, I just builded a App for my Youtube-Channel. For this I used JSON to get the information and pass that into my ListView over a SimpleListAdapter.

现在,图像不到风度显示出来,因为我只是URL链接到我的ImageView。

Now, the image dosn't show up, because I only link the URL to my ImageView.

我怎样才能下载图像并将其链接到我的ListView的正确路线。我找到了一种方法来下载他们,但是这不是动态地,我怎么可以这样做:
如何下载图片

How can I download the Image and link it to the correct line of my ListView. I found a way to download them but this isn't dynamicly, how can I do this: How to Download Image

一个codeSAMPLE或教程将是巨大的!到这里,你找到我活动的code和布局文件中。

A Codesample or a Tutorial would be great! Down here you find the Code of my Activity and the Layout-File.

code

test2.class

test2.class

package de.stepforward;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;



import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class test2 extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    String result = "";
    String line = null;
    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();


    //get the Data from URL
    try{
    URL url = new URL("http://gdata.youtube.com/feeds/mobile/users/TheStepForward/uploads?alt=json&format=1"); 

    URLConnection conn = url.openConnection();
    StringBuilder sb = new StringBuilder();
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    //read d response till d end
    while ((line = rd.readLine()) != null) {
    sb.append(line + "\n");
    }
    result = sb.toString();
    Log.v("log_tag", "Append String " + result);
    } catch (Exception e) {
    Log.e("log_tag", "Error converting result " + e.toString());
    }

    try{
        JSONObject json = new JSONObject(result);
        JSONObject feed = json.getJSONObject("feed");
        JSONArray entrylist = feed.getJSONArray("entry");

        for(int i=0;i<entrylist.length();i++){
            //Get Title
            JSONObject movie = entrylist.getJSONObject(i);
            JSONObject title = movie.getJSONObject("title");
            String txtTitle = title.getString("$t");
            Log.d("Title", txtTitle);

            //Get Description
            JSONObject content = movie.getJSONObject("content");
            String txtContent = content.getString("$t");
            Log.d("Content", txtContent);

            //Get Link
            JSONArray linklist = movie.getJSONArray("link");
            JSONObject link = linklist.getJSONObject(4);
            String txtLink = link.getString("href");
            Log.d("Link", txtLink);


            //Get Thumbnail
            JSONObject medialist = movie.getJSONObject("media$group");
            JSONArray thumblist = medialist.getJSONArray("media$thumbnail");
            JSONObject thumb = thumblist.getJSONObject(3);
            String txtThumb = thumb.getString("url");
            Log.d("Thumb", txtThumb.toString());


            //String Array daraus machen und in Hashmap füllen
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("Thumb", txtThumb);
            map.put("Title", txtTitle);
            map.put("Content", txtContent);
            map.put("Link", txtLink);
            mylist.add(map);

        }
        ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.lit, 
                new String[] { "Thumb","Title","Content","Link"}, 
                new int[] { R.id.img_video,R.id.txt_title,R.id.txt_subtitle});      
        setListAdapter(adapter);



    }catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
        }
}
}


lit.xml


lit.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/Placeholder"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


    <LinearLayout
        android:id="@+id/Content"
        android:layout_width="fill_parent"
        android:layout_height="60dp">

        <ImageView
            android:id="@+id/img_video"
            android:layout_width="80dp"
            android:layout_height="60dp">
        </ImageView>

        <TableLayout
            android:id="@+id/Text"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_below="@+id/Content" 
            android:paddingLeft="5dp">

            <TableRow
                android:id="@+id/TextTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/txt_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingBottom="5dp"
                    android:textColor="#FFFFFF"
                    android:textStyle="bold" >
                </TextView>
            </TableRow>

                <TableRow
                     android:id="@+id/TextContent"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content" >

                     <TextView
                        android:id="@+id/txt_subtitle"
                        android:layout_width="wrap_content"
                        android:layout_height="40dp"
                        android:paddingBottom="5dp"
                        android:textColor="#FFFFFF" android:textSize="7dp">
                     </TextView>
            </TableRow>

        </TableLayout>

    </LinearLayout>

</RelativeLayout>


感谢您提前帮助。


Thank you for the help in Advance.

此致

Safari浏览器

推荐答案

您好:这个问题已经得到了在这里得到解答:<一href=\"http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview\">Android - 我该如何进行图像的延迟加载ListView中 - 你需要的是一个延迟加载的ImageView

Hello this question already got answered here: Android - How do I do a lazy load of images in ListView - What you need is a lazy loading ImageView.

这篇关于得到一个URL动态地的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆