編輯:關於android開發
1 package com.lixu.listviewrefresh; 2 3 import java.util.ArrayList; 4 5 import android.app.Activity; 6 import android.os.Bundle; 7 import android.widget.AbsListView; 8 import android.widget.AbsListView.OnScrollListener; 9 import android.widget.ArrayAdapter; 10 import android.widget.ListView; 11 12 public class MainActivity extends Activity { 13 private ArrayList<String> data; 14 private ArrayAdapter<String> mMyAdapter; 15 16 @Override 17 protected void onCreate(Bundle savedInstanceState) { 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.activity_main); 20 21 data = new ArrayList<String>(); 22 23 for (int i = 0; i < 30; i++) { 24 data.add("測試數據" + i); 25 } 26 27 ListView lv = (ListView) findViewById(R.id.listview); 28 29 mMyAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data); 30 31 lv.setAdapter(mMyAdapter); 32 33 lv.setOnScrollListener(new OnScrollListener() { 34 private int firstVisibleItem; 35 private int visibleItemCount; 36 private int totalItemCount; 37 38 @Override 39 public void onScrollStateChanged(AbsListView view, int scrollState) { 40 // 當滑動停止的時候判斷 41 if (OnScrollListener.SCROLL_STATE_IDLE == scrollState) { 42 43 if (firstVisibleItem == 0) { 44 45 data.add(0, "增加頭部數據" + (totalItemCount + 1)); 46 47 mMyAdapter.notifyDataSetChanged(); 48 49 } 50 } 51 52 if (OnScrollListener.SCROLL_STATE_IDLE == scrollState) { 53 54 if ((firstVisibleItem + visibleItemCount) == totalItemCount) { 55 56 data.add("增加尾部數據" + (totalItemCount + 1)); 57 58 mMyAdapter.notifyDataSetChanged(); 59 60 } 61 } 62 63 } 64 65 @Override 66 public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 67 68 this.firstVisibleItem = firstVisibleItem; 69 this.visibleItemCount = visibleItemCount; 70 this.totalItemCount = totalItemCount; 71 72 } 73 }); 74 75 } 76 77 }
效果圖:
Android自定義控件4--優酷菜單的菜單鍵及細節補充,android4--在上篇文章中實現了優酷菜單執行動畫,本文接著完善已經實現的動畫功能 本文地址:http://
Android系統 應用圖標顯示未讀消息數(BadgeNumber) 桌面app圖標的角標顯示 Android系統 小米,三星,索尼手機發送桌面快鍵提醒數字圖標,在
Android安全開發之淺談密鑰硬編碼,android淺談密鑰Android安全開發之淺談密鑰硬編碼 作者:伊樵、呆狐@阿裡聚安全 1 簡介 在阿裡聚安全的
android:eclipse看著很舒服的字體和啟動速度很快android模擬器 下載後 在c盤windows/font文件夾下添加解壓後的字體即可 然後重啟ecli