resolveUri ListView中失败的坏位来自JSON [英] resolveUri failed on bad bitmap in ListView from JSON

查看:146
本文介绍了resolveUri ListView中失败的坏位来自JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是要显示一个imagen画质为从JSON readed列表视图,我读了很多关于这个问题的帖子,但没有一个彻底解决它。我cathc与 URL字符串imagen画质= e.getString(IMG_ preview_1); 然后加入

My problem is to show an imagen into a listview readed from JSON, I read a lot of posts about the issue but no one solved it completely. I cathc the url with String imagen = e.getString("img_preview_1"); then added it into

HashMap<String, String> map = new HashMap<String, String>();
map.put("imagen", imagen);

这是我的适配器与字符串和图像

This is my adapter with a String and the image

ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.activity_videos_categoria, 
                        new String[] { "title", "imagen" }, 
                        new int[] { R.id.from , R.id.imageView1});

        setListAdapter(adapter);

我试图在地图ASN对象chenging类型,但仍同样的问题。

I tried chenging the type in the Map asn Object but still same problem

在LogCat中的误差resolveUri失败的坏的位图

The error in LogCat is resolveUri failed on bad bitmap

感谢您

推荐答案

这里的问题是,你可以直接设置网​​址(这是字符串类型)的的ImageView 并要求 SimpleAdapter 将其绑定到的ImageView 。我建议你​​使用其他适配器,在我的下面code。因为 SimpleAdapter SimpleCursorAdapter 当你在本地(源码)数据库中的数据大多采用来使内容直接反映在列表视图。但在这里,你从服务器的数据。所以在这里,你去用它。

The problem here is you are setting a url(Which is of String type) directly to the imageview and requesting the SimpleAdapter to bind it to the imageview. I would suggest you to use other adapters as in my below code. Because SimpleAdapter and SimpleCursorAdapter are mostly used when you have data in the local(sqlite) database to make the content reflected directly on the listview. But here you get the data from the server. So here you go with it.

public class CustomListAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 

    public CustomListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
           vi = inflater.inflate(R.layout.list_row, null); //This should be your row layout

        TextView titleTextView = (TextView)vi.findViewById(R.id.title); // title
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.imageview1); //image

        HashMap<String, String> localhash = new HashMap<String, String>();
        localhash = data.get(position);

        String currenttitle = localhash.get("title");
        String imagepath = localhash.get("imagen");

        titleTextView.setText(currenttitle);

        if(!imagepath.equals(""))
        {
        imageLoader.DisplayImage(imagepath , thumb_image);

        }
        return vi;
    }

}

您设定的上述适配器与列表视图在下面的方法。包括以下code你从网络上加载数据之后。要加载来自服务器的数据,请确保您不要在UI线程上运行的网络操作。为此,您可以使用AsyncTask的,处理程序,服务等,如果您使用的AsyncTask,包括 onPostExecute下面的线()

You set the above adapter to your listview in the below way. Include the below code after you load the data from the network. To load the data from the server, make sure you don't run the network operations on UI thread. For this you can make use of AsyncTask,Handlers, Service etc., If you use AsyncTask, include the below lines in onPostExecute().

CustomListAdapter adapter = new CustomListAdapter(YourActivity.this, dataArrayList);
listView.setAdapter(adapter); 

希望这有助于和回答延迟顺便说一句抱歉。

Hope this helps and btw sorry for the delay in answering.

这篇关于resolveUri ListView中失败的坏位来自JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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