android– 通过简单的适配器在imageview中显示位图图像

android– 通过简单的适配器在imageview中显示位图图像,第1张

概述我正在从网址获取图像.我在listview中使用imageview.我想将位图图像列表添加到列表项的每一行.我使用SimpleAdapter但是imageview显示为空白.我的代码如下!ArrayList<HashMap<String,Bitmap>>mylist=newArrayList<HashMap<String,Bitmap>>();Bundlebundle=this.ge

我正在从网址获取图像.我在ListvIEw中使用imagevIEw.我想将位图图像列表添加到列表项的每一行.我使用SimpleAdapter但是imagevIEw显示为空白.我的代码如下!

 ArrayList<HashMap<String, Bitmap>> myList = new ArrayList<HashMap<String, Bitmap>>();    Bundle bundle = this.getIntent().getExtras();     get = bundle.getString("name");     try{            httpClIEnt httpclIEnt = new DefaulthttpClIEnt();            httpPost httppost = new httpPost("http://www.propertyhookup.com/mobile/propertyList.PHP");            nameValuePairs = new ArrayList<nameValuePair>(1);            nameValuePairs.add(new BasicnameValuePair("zipcode", get.trim()));            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));            httpResponse response = httpclIEnt.execute(httppost);            httpentity entity = response.getEntity();            is = entity.getContent();    }catch(Exception e){            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();    }  //convert response to string    try{            BufferedReader reader = new BufferedReader(new inputStreamReader(is,"iso-8859-1"),8);            StringBuilder sb = new StringBuilder();            String line = null;            while ((line = reader.readline()) != null) {                    sb.append(line + "\n");            }            is.close();            result=sb.toString();    }catch(Exception e){            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();    }    if(result.length()<= 7){        Toast.makeText(getApplicationContext(), "No propertIEs for this zipcode or check your zipcode ", Toast.LENGTH_LONG).show();        //text.setText("No propertIEs for this zipcode or check your zipcode");    }    else{    try{     jArray = new JsONObject(result);                }catch(JsONException e){        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();    }    //JsONObject Json = JsONfunctions.getJsONfromURL("http://192.168.1.111/propertyhookup.com/mobile/propertyList.PHP");    try{        JsONArray  earthquakes = jArray.getJsONArray("earthquakes");        for(int i=0;i<10;i++){                                  map = new HashMap<String, Bitmap>();            //HashMap<String, Drawable> map1 = new HashMap<String, Drawable>();            JsONObject e = earthquakes.getJsONObject(i);            if(e.getString("property_type").contains("1")) {                proptype ="Single Family Home";            }else if(e.getString("property_type").contains("2")) {                proptype="Condo";            }else if(e.getString("property_type").contains("3")) {                proptype="Townhouse";            }            if(e.getString("estimated_price").contains("0")) {                estimate = "Not Enough Market Value";                //estimat = (TextVIEw) findVIEwByID(R.ID.estimat);                //estimat.setTextcolor(color.rgb(0, 0, 23));            }else {                estimate = "$"+e.getString("estimated_price");            }            photo = e.getString("photo1");            drawable = LoadImageFromWebOperations(photo);            //text.setimageDrawable(d);            try            {                    aURL = new URL(photo);            }            catch (MalformedURLException e1)            {                    // Todo auto-generated catch block                    e1.printstacktrace();            }            URLConnection conn = null;            try            {                    conn = aURL.openConnection();            }            catch (IOException e1)            {                    // Todo auto-generated catch block                    e1.printstacktrace();            }            try            {                    conn.connect();            }            catch (IOException e1)            {                    // Todo auto-generated catch block                    e1.printstacktrace();            }            inputStream is = null;            try            {                    is = conn.getinputStream();            }            catch (IOException e1)            {                    // Todo auto-generated catch block                    e1.printstacktrace();            }            BufferedinputStream bis = new    BufferedinputStream(is,8*1024);            Bitmap bm = BitmapFactory.decodeStream(bis);            map.put(photos, bm);            myList.add(map);        }           }catch(JsONException e)        {        Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG).show();    }    SimpleAdapter adapter = new SimpleAdapter(this, myList , R.layout.main4,                    new String[] { "percent","propertyID",  "cityname", "statecode", "propertytype", "footage", "bathroom", "bedroom", "price", "estimated", "photos" },                    new int[] { R.ID.percent, R.ID.property_ID,  R.ID.city_name, R.ID.state_code, R.ID.prop_type, R.ID.foot, R.ID.bath, R.ID.bed, R.ID.List, R.ID.estimat, R.ID.image});    setlistadapter(adapter);

解决方法:

我认为是因为你从网上下载图像,你需要在ASYNC中看到无痛的线索下载图像,然后刷新图像视图.

总结

以上是内存溢出为你收集整理的android – 通过简单的适配器在imageview中显示位图图像全部内容,希望文章能够帮你解决android – 通过简单的适配器在imageview中显示位图图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1119675.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存