以下は私のコードです。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が1つあります。listadapterをオーバーライドして、動的画像をリストビューにロードする方法。
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);