編輯:關於Android編程
效果圖:
此程序主要的知識點是:SimpleAdapter本身是不支持網絡圖片的, 如果在Map.put(a,b)中 b為一個Bitmap,程序不會報紅色字體,而是在控制台輸出綠色的字體,如下
05-10 15:46:45.474: I/System.out(846): resolveUri failed on bad bitmap uri: android.graphics.Bitmap@43e40c08
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+0qrP68q1z9bP1Mq+zfjC5828xqzG5Mq1uty88rWlo6zKudPDU2ltcGxlQWRhcHRlctbQtcS3vbeoc2ltcGxlQWRhcHRlci5zZXRWaWV3QmluZGVyo6ijqaGjPC9wPgo8cD48YnI+CjwvcD4KPHA+PHByZSBjbGFzcz0="brush:java;">simpleAdapter.setViewBinder(new ViewBinder() {
@Override
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if (view instanceof ImageView && data instanceof Bitmap) {
ImageView iv = (ImageView) view;
iv.setImageBitmap((Bitmap) data);
return true;
}
return false;
}
});
new SimpleAdapter(MainActivity.this,getData(), R.layout.t, new String[] { "images" },new int[] { R.id.ImageVIew_main });
list
既然是網絡圖片,那就需要權限
代碼如下:
MainActivity.java
public class MainActivity extends ActionBarActivity { ListView listView; List> data; String str[] = { "", //自己添加圖片網址 h t t p :// "", "", "" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.LV_main); SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, getData(), R.layout.t, new String[] { "images" }, new int[] { R.id.ImageVIew_main }); simpleAdapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { if (view instanceof ImageView && data instanceof Bitmap) { ImageView iv = (ImageView) view; iv.setImageBitmap((Bitmap) data); return true; } return false; } }); listView.setAdapter(simpleAdapter); } public List > getData() { data = new ArrayList >(); for (int i = 0; i < str.length; i++) { Map map = new HashMap (); map.put("images", returnBitMap(str[i])); data.add(map); } return data; } public Bitmap returnBitMap(String url) { URL myFileUrl = null; Bitmap bitmap = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl .openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } }
t.xml
Android學習筆記二十五之ListView多布局實現 這一節是介紹ListView這個控件的最後一節,實現一個Item的多布局。像我們經常在用的各種即時通訊工具,Q
要想使用Eclipse開發Android應用,首先要安裝一個ADT插件,在此記錄一下在Eclipse中采用在線安裝的方式ADT插件,我使用的Eclipse版本是:ecli
一、GPU硬件加速1、概述GPU英文全稱Graphic Processing Unit,中文翻譯為“圖形處理器”。與CPU不同,GPU是專門為處理
我們常用context.startService()來啟動一個service,下面來分析一下這個service的啟動過程,下圖是service啟動的序列圖: st