毛孩市集 (友站連結)

顯示具有 ListView 標籤的文章。 顯示所有文章
顯示具有 ListView 標籤的文章。 顯示所有文章

2011年5月24日 星期二

在ListView顯示網路圖片+快取

這篇的重點是在ListView裡顯示網路圖片
並且加到cache裡,如果還在下載就顯示ProgressBar


1. 

2.


3. 

4.


先自訂一個類別GetWebImg
private HashMap<String, Bitmap> picmap = new HashMap<String, Bitmap>();
//宣告一個HashMap用來存網址及圖片用的

2011年5月20日 星期五

ListView之自動重新整理與載入

今天來介紹一些ListView的用法
主要目的是當ListView拉到頂時自動重新整理、拉到底時自動載入更多。





 一開始先建立兩個layout,分別是head.xml、foot.xml
分別用來顯示重新整理中、載入中的文字


接下來直接來看主要的程式碼
這些變數是用來判斷要不要更新或載入資料
boolean shouldRefresh=true,isRefreshing=false;
boolean shouldLoadData=true,isLoadingData=false;




head = LayoutInflater.from(this).inflate(R.layout.head, null);//將head.xml轉為view
headtext = (TextView) head.findViewById(R.id.head);//取得head裡的TextView
foot = LayoutInflater.from(this).inflate(R.layout.foot, null);//將foot.xml轉為view
list = getListView();//取得ListView
list.addHeaderView(head, null, false);//就addHeaderView...
list.addFooterView(foot, null, false);//就addFooterView...


mydataAdapter = new MydataAdapter(Main.this,alldata);
setListAdapter(mydataAdapter);//一定要放在addHeaderView及addFooterView的後面