編輯:關於Android編程
在前面的兩篇文章中,我們講到了關於ArrayAdapter的使用。用ArrayAdapter來在ListView中展示數據是很不錯的,但是很多時候,我們的ListView中,可不只是展示文字,我們還想展示圖片呢。
可能有些朋友剛才會問,第二篇不是已經可以展示圖片了嗎?是的呀,但是它就只能展示我們在xml中定義給它的那一張啊。
而究其原因,其實是因為我們傳給它的數據源就只有字符串,沒有傳給圖片給它,而事實上,我們也只能傳文字給它,因為它用的是TextView嘛。
所以,光用ArrayAdapter顯然不夠豐富多彩,生活呀,總得有點不一樣吧。
接下來我們就來看看在Android中關於SimpleAdapter的使用吧。
我們定義了1個ImageView控件和兩個TextView控件。 接下來我們看看MainActivity中的代碼:
List
/**
* Constructor
*
* @param context The context where the View associated with this SimpleAdapter is running
* @param data A List of Maps. Each entry in the List corresponds to one row in the list. The
* Maps contain the data for each row, and should include all the entries specified in
* "from"
* @param resource Resource identifier of a view layout that defines the views for this list
* item. The layout file should include at least those named views defined in "to"
* @param from A list of column names that will be added to the Map associated with each
* item.
* @param to The views that should display column in the "from" parameter. These should all be
* TextViews. The first N views in this list are given the values of the first N columns
* in the from parameter.
*/
public SimpleAdapter(Context context, List extends Map> data,
int resource, String[] from, int[] to) {
mData = data;
mResource = mDropDownResource = resource;
mFrom = from;
mTo = to;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} 1)context,上下文
2)List extends Map
android生命周期深入分析(二)
在 Android 中,多數情況下每個程序都是在各自獨立的 Linux 進程中運行的。當一個程序或其某些部分被請求時,它的進程就“出生”了;當這個程序沒有必要再運行下去且
Android學習個人筆記-百度地圖定位sdk的使用
雖然自己已經完成了百度地圖的調用,但是在使用過程中產生很多的疑問,在不斷的百度各種大神的作品後才慢慢的調試出來,所以覺得作為新手自己應該把這個過程記錄下來。尤其是自己在找
android編程之XML文件解析方法詳解(附源碼)
本文實例講述了android編程之XML文件解析方法。分享給大家供大家參考,具體如下:在android開發中,經常用到去解析xml文件,常見的解析xml的方式有一下三種:
Android實現動態高斯模糊效果
高斯模糊是什麼?高斯模糊(英語:Gaussian Blur),也叫高斯平滑,是在Adobe Photoshop、GIMP以及Paint.NET等圖像處理軟件中廣泛使用的處