Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.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
Java 在GridView中使用毕加索:ImageView存在但没有图像_Java_Android_Gridview_Picasso - Fatal编程技术网

Java 在GridView中使用毕加索:ImageView存在但没有图像

Java 在GridView中使用毕加索:ImageView存在但没有图像,java,android,gridview,picasso,Java,Android,Gridview,Picasso,我正在尝试实现毕加索来帮助将图像加载到GridView中。目前,下面的代码运行没有任何问题,但GridView项只是空白。我知道特定的ImageView实际上就在那里,因为如果我选择它并按住,选中的状态drawable将被激活,正如您在屏幕截图中看到的那样 你能帮我找到问题吗?谢谢 GalleryFragment.java: GalleryAdapter.java扩展了BaseAdapter: fragment_gallery.xml: 这就是我如何用GridLayout成功实现毕加索库的方法。

我正在尝试实现毕加索来帮助将图像加载到GridView中。目前,下面的代码运行没有任何问题,但GridView项只是空白。我知道特定的ImageView实际上就在那里,因为如果我选择它并按住,选中的状态drawable将被激活,正如您在屏幕截图中看到的那样

你能帮我找到问题吗?谢谢

GalleryFragment.java:

GalleryAdapter.java扩展了BaseAdapter:

fragment_gallery.xml:


这就是我如何用GridLayout成功实现毕加索库的方法。。。要求您对项目使用a,我也遇到了同样的问题,但使用GridLayout解决了这个问题:

public class ImageHandler {

    private static Picasso instance;

    public static Picasso getSharedInstance(Context context)
    {
        if(instance == null)
        {
            instance = new Picasso.Builder(context).executor(Executors.newSingleThreadExecutor()).memoryCache(Cache.NONE).indicatorsEnabled(true).build();
            return instance;
        }
        else
        {
            return instance;
        }
    }
}
在我实现这个类之后,这里是如何在代码中访问并将图像加载到ImageView中的,ImageView是GridLayout的一部分

// imString = "http://filepath.file.jpg" as example


        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        GridLayout grid = (GridLayout) findViewById(R.id.viewAllGrid);
        grid.canScrollVertically(1);
        ImageButton image;

        for(int i = 0; i < itemsList.size(); i++){
            aContainer= (LinearLayout) inflater.inflate(R.layout.layout_container, null);
            image = (ImageButton) aContainer.findViewById(R.id.imageViewOrButton);
            ImageHandler.getSharedInstance(getApplicationContext()).load(imString).skipMemoryCache().fit().into(image);
            grid.addView(aContainer);
        }
这是容器的布局

<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10dp"
    android:id="@+id/Container"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageButton
        android:layout_width="100dp"
        android:layout_height="130dp"
        android:background="@null"
        android:id="@+id/seriesThumbnail"/>

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textStyle="bold"
        android:textColor="#ffffffff"
        android:id="@+id/title"
        android:autoText="false"
        android:ellipsize="end"
        android:maxLines="1" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/publisher"
        android:text="Francis Chan"
        android:maxLines="1"
        android:ellipsize="end" />

</LinearLayout>
下面是viewAllGrid布局模式

<GridLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:paddingLeft="20dp"
            android:id="@+id/viewAllGrid"
            android:layout_gravity="center_horizontal"
            android:columnCount="3"
            android:layout_weight=".8"
            android:orientation="horizontal">
        </GridLayout>

我也有同样的问题,那是因为我缺少权限

<!-- This is required for Picasso to work. -->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- The following permissions are OPTIONAL. -->

<!-- Used to adjust the work load depending on the type of network the device is using. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

查看这个链接@user3676184实际上我在学习如何实现毕加索时已经读过这篇文章,我的方法非常相似。您是否看到可能导致我出错的其他原因?我已经在user3676184的链接中尝试了实现,上面的实现来自官方的Picasso github,但都会导致相同的问题。Dude检查这一行,他们正在传递两个参数-final类SampleGridViewAdapter Extendes BaseAdapter{private final Context;private final List url=new ArrayList;
// imString = "http://filepath.file.jpg" as example


        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        GridLayout grid = (GridLayout) findViewById(R.id.viewAllGrid);
        grid.canScrollVertically(1);
        ImageButton image;

        for(int i = 0; i < itemsList.size(); i++){
            aContainer= (LinearLayout) inflater.inflate(R.layout.layout_container, null);
            image = (ImageButton) aContainer.findViewById(R.id.imageViewOrButton);
            ImageHandler.getSharedInstance(getApplicationContext()).load(imString).skipMemoryCache().fit().into(image);
            grid.addView(aContainer);
        }
<LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10dp"
    android:id="@+id/Container"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageButton
        android:layout_width="100dp"
        android:layout_height="130dp"
        android:background="@null"
        android:id="@+id/seriesThumbnail"/>

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textStyle="bold"
        android:textColor="#ffffffff"
        android:id="@+id/title"
        android:autoText="false"
        android:ellipsize="end"
        android:maxLines="1" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/publisher"
        android:text="Francis Chan"
        android:maxLines="1"
        android:ellipsize="end" />

</LinearLayout>
<GridLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:paddingLeft="20dp"
            android:id="@+id/viewAllGrid"
            android:layout_gravity="center_horizontal"
            android:columnCount="3"
            android:layout_weight=".8"
            android:orientation="horizontal">
        </GridLayout>
<!-- This is required for Picasso to work. -->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- The following permissions are OPTIONAL. -->

<!-- Used to adjust the work load depending on the type of network the device is using. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>