【问题标题】:Sometimes my icons in my list view are not showing有时我的列表视图中的图标没有显示
【发布时间】:2011-09-29 07:38:42
【问题描述】:

我的问题是我已经实现了一个自定义 arrayadapter,它从 url 获取图像并将它们设置为 imageview。它起作用了,有点。有时有些图像没有显示出来。有时它只是一个图像,有时它是三个并且没有明显的顺序。唯一合理一致的是它似乎是我的数组列表中的第 3 个图像。

我的自定义适配器:

public CustomAdapter( Context context, int textViewResourceId, List items )
{
        super( context, textViewResourceId, items );
        this.items = items;
}

@Override
public View getView( int position, View convertView, ViewGroup parent )
{
    View v = convertView;
    if ( v == null )
    {
        LayoutInflater vi =  ( LayoutInflater ) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        v = vi.inflate( R.layout.list_item, parent, false );
    }
    Object o = items.get( position );
    if  ( o != null )
    {
            TextView textView = ( TextView ) v.findViewById( R.id.listItem );
            ImageView imageView = ( ImageView ) v.findViewById( R.id.icon );

            if ( textView != null )
            {
                textView.setText( o.toString() );
            }
            if ( imageView != null )
            {
                if ( o instanceof XmlGuide )
                {
                    try
                    {
                        imageView.setImageBitmap( downloadIcon( ( ( XmlGuide ) o ).getIcon() ) );
                    }
                    catch( Exception e )
                    {
                        e.printStackTrace();
                    }
                }
            }
    }
    return v;
}

private Bitmap downloadIcon( String uri ) throws Exception
{
    URL url = new URL( uri );
    InputStream stream = url.openStream();
    Bitmap icon = BitmapFactory.decodeStream( stream );
    stream.close();
    return icon;
}

【问题讨论】:

    标签: android android-arrayadapter android-imageview custom-adapter


    【解决方案1】:

    不建议在 getView 期间使用阻塞网络部分。

    使用

    setImageUri(Uri.parse(o.getIcon());
    

    当然更好。

    【讨论】:

    • 我的 getIcon() 返回一个字符串,它与 setImageUri 并不能很好地配合
    • 这就是我写“Uri.parse(o.getIcon())”的原因
    【解决方案2】:

    我终于找到了问题所在。问题是 Android

    您可以在此处阅读更多信息:http://code.google.com/p/android/issues/detail?id=6066

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多