下面是我的代码。我正在通过 JSONArray 获取图像的 url。然后我将图像转换为位图图像并存储在哈希表中。
我正在使用 ImageView 在列表视图中显示图像。所以我使用简单的适配器来获取图像。但是图像没有加载。
请帮帮我,我是Android新手!!!!!!
ArrayList<Hashtable<String, Bitmap>> mylist1 = new ArrayList<Hashtable<String, Bitmap>>();
try{
JSONArray earthquakes = json.getJSONArray("earthquakes");
for(int i=0;i<10;i++){
imagemap = new Hashtable<String, Bitmap>();
JSONObject e = earthquakes.getJSONObject(i);
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);
imagemap.put("im",bm);
mylist1.add(imagemap);
ListAdapter adapter = new SimpleAdapter(this,mylist1,R.layout.main,new String[] {"im"},new int[] {R.id.image});
setListAdapter(adapter);
更新:
下面是我用来将字符串加载到列表视图中的文本字段的 ArrayAdapter。我有一个 ImageView 在里面。如何覆盖列表适配器以将动态图像加载到列表视图中。
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main4,
new String[] { "percent","propertyid", "cityname", "statecode", "propertytype", "footage", "bathroom", "bedroom", "price", "estimated" },
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});
setListAdapter(adapter);