-1

我试图实现从这里获得的图像异步任务:

http://schimpf.es/asynctask-for-image-download/

然后我尝试在我的代码中执行它,如下所示:

ImageView im1 = (ImageView) findViewById(R.id.image);
ImageDownloadTask imageD = new ImageDownloadTask(im1);
imageD.execute(e.mediumLabel);

图片永远加载不出来......

我的 xml 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/beerTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="40sp"
        android:textStyle = "bold"
        android:padding="5dip"
        >
    </TextView>

    <ImageView android:id="@+id/image"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_margin="10dip"/>

    <Button
        android:id="@+id/buttonBrewery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text="" />
    <Button
        android:id="@+id/buttonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:text="" />

    <TextView
        android:id="@+id/beerDEscriptionTitle"
        android:textStyle = "bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="20sp"
        android:text="Description"
        android:padding="5dip"
        ></TextView>
    <TextView
        android:id="@+id/beerDescription"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="15sp"
        android:padding="5dip"

        ></TextView>

</LinearLayout>
</ScrollView>
4

3 回答 3

3

帮自己一个忙并使用毕加索:http ://square.github.io/picasso/

于 2013-06-19T21:54:26.220 回答
1

没有奏效也就不足为奇了。ASyncTask 中的“url”字段永远不会设置。在 ASyncTask 中更改这一行:

 InputStream in = new java.net.URL(url).openStream();

要实际使用在执行(字符串)中发送的参数......这应该工作的链接:

 InputStream in = new java.net.URL(params[0]).openStream();
于 2013-06-19T23:11:37.343 回答
0

该 AsyncTask 图像加载器类中的 URL 永远不会在任何地方设置,图像永远不会下载。在调用 execute() 时将其设置在构造函数或参数中。我会考虑使用其他加载图像的方法。

此外,请确保您拥有适当的 Internet 权限:

<uses-permission android:name="android.permission.INTERNET">
于 2013-06-19T21:49:40.980 回答