Android GridView 分頁載入資料
如圖:
Java程式碼
- package cn.anycall.ju;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.app.Activity;
- import android.content.ActivityNotFoundException;
- import android.content.Context;
- import android.content.Intent;
- import android.content.pm.ResolveInfo;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Looper;
- import android.os.Message;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.Window;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.GridView;
- import android.widget.Toast;
- import cn.anycall.ju.ScrollLayout.OnScreenChangeListenerDataLoad;
- /**
- * GridView分頁顯示安裝的應用程式
- */
- publicclass AllAppList extends Activity {
- private ScrollLayout mScrollLayout;
- privatestaticfinalfloat APP_PAGE_SIZE = 4.0f;
- private Context mContext;
- private
- public MyHandler myHandler;
- publicint n=0;
- private DataLoading dataLoad;
- @Override
- protectedvoid onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- mContext = this;
- setContentView(R.layout.main);
- dataLoad = new DataLoading();
- mScrollLayout = (ScrollLayout)findViewById(R.id.ScrollLayoutTest);
- myHandler = new MyHandler(this,1);
- //起一個執行緒更新資料
- MyThread m = new MyThread();
- new Thread(m).start();
- }
- /**
- * gridView 的onItemLick響應事件
- */
- public OnItemClickListener listener = new OnItemClickListener() {
- publicvoid onItemClick(AdapterView<?> parent, View view, int position,
- long id) {
- // TODO Auto-generated method stub
- System.out.println("position="+position);
- }
- };
- @Override
- protectedvoid onDestroy() {
- // TODO Auto-generated method stub
- android.os.Process.killProcess(android.os.Process.myPid());
- super.onDestroy();
- }
- @Override
- publicboolean onKeyDown(int keyCode, KeyEvent event) {
- // TODO Auto-generated method stub
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- finish();
- returntrue;
- }
- returnsuper.onKeyDown(keyCode, event);
- }
- // 更新後臺資料
- class MyThread implements Runnable {
- publicvoid run() {
- try {
- Thread.sleep(1000*3);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String msglist = "1";
- Message msg = new Message();
- Bundle b = new Bundle();// 存放資料
- b.putString("rmsg", msglist);
- msg.setData(b);
- AllAppList.this.myHandler.sendMessage(msg); // 向Handler傳送訊息,更新UI
- }
- }
- class MyHandler extends Handler {
- private AllAppList mContext;
- public MyHandler(Context conn,int a) {
- mContext = (AllAppList)conn;
- }
- public MyHandler(Looper L) {
- super(L);
- }
- // 子類必須重寫此方法,接受資料
- @Override
- publicvoid handleMessage(Message msg) {
- // TODO Auto-generated method stub
- super.handleMessage(msg);
- Bundle b = msg.getData();
- String rmsg = b.getString("rmsg");
- if ("1".equals(rmsg)) {
- // do nothing
- List<Map> list = new ArrayList<Map>();
- for(int i =0;i<16;i++){
- n++;
- Map map = new HashMap();
- map.put("name", n);
- list.add(map);
- }
- int pageNo = (int)Math.ceil( list.size()/APP_PAGE_SIZE);
- for (int i = 0; i < pageNo; i++) {
- GridView appPage = new GridView(mContext);
- // get the "i" page data
- appPage.setAdapter(new AppAdapter(mContext, list, i));
- appPage.setNumColumns(2);
- appPage.setOnItemClickListener(listener);
- mScrollLayout.addView(appPage);
- }
- //載入分頁
- pageControl = (PageControlView) findViewById(R.id.pageControl);
- pageControl.bindScrollViewGroup(mScrollLayout);
- //載入分頁資料
- dataLoad.bindScrollViewGroup(mScrollLayout);
- }
- }
- }
- //分頁資料
- class DataLoading {
- privateint count;
- publicvoid bindScrollViewGroup(ScrollLayout scrollViewGroup) {
- this.count=scrollViewGroup.getChildCount();
- scrollViewGroup.setOnScreenChangeListenerDataLoad(new OnScreenChangeListenerDataLoad() {
- publicvoid onScreenChange(int currentIndex) {
- // TODO Auto-generated method stub
- generatePageControl(currentIndex);
- }
- });
- }
- privatevoid generatePageControl(int currentIndex){
- //如果到最後一頁,就載入16條記錄
- if(count==currentIndex+1){
- MyThread m = new MyThread();
- new Thread(m).start();
- }
- }
- }
- }
Java程式碼
- package cn.anycall.ju;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import android.content.Context;
- import android.content.pm.PackageManager;
- import android.content.pm.ResolveInfo;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- import cn.anycall.ju.R;
- publicclass AppAdapter extends BaseAdapter {
- private List<Map> mList;
- private Context mContext;
- publicstaticfinalint APP_PAGE_SIZE = 4;
- private PackageManager pm;
- public AppAdapter(Context context, List<Map> list, int page) {
- mContext = context;
- pm = context.getPackageManager();
- mList = new ArrayList<Map>();
- int i = page * APP_PAGE_SIZE;
- int iEnd = i+APP_PAGE_SIZE;
- while ((i<list.size()) && (i<iEnd)) {
- mList.add(list.get(i));
- i++;
- }
- }
- publicint getCount() {
- // TODO Auto-generated method stub
- return mList.size();
- }
- public Object getItem(int position) {
- // TODO Auto-generated method stub
- return mList.get(position);
- }
- publiclong getItemId(int position) {
- // TODO Auto-generated method stub
- return position;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- Map appInfo = mList.get(position);
- AppItem appItem;
- if (convertView == null) {
- View v = LayoutInflater.from(mContext).inflate(R.layout.app_item, null);
- appItem = new AppItem();
- appItem.mAppIcon = (ImageView)v.findViewById(R.id.imgdetail);
- appItem.mAppName = (TextView)v.findViewById(R.id.tuaninfo);
- v.setTag(appItem);
- convertView = v;
- } else {
- appItem = (AppItem)convertView.getTag();
- }
- // set the icon
- appItem.mAppIcon.setImageResource(R.drawable.icon);
- // set the app name
- appItem.mAppName.setText(appInfo.get("name").toString());
- return convertView;
- }
- /**
- * 每個應用顯示的內容,包括圖示和名稱
- * @author Yao.GUET
- *
- */
- class AppItem {
- ImageView mAppIcon;
- TextView mAppName;
- }
- }
Java程式碼
- package cn.anycall.ju;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import cn.anycall.ju.R;
- import cn.anycall.ju.ScrollLayout.OnScreenChangeListener;
- publicclass PageControlView extends LinearLayout {
- private Context context;
- privateint count;
- publicvoid bindScrollViewGroup(ScrollLayout scrollViewGroup) {
- this.count=scrollViewGroup.getChildCount();
- System.out.println("count="+count);
- generatePageControl(scrollViewGroup.getCurrentScreenIndex());
- scrollViewGroup.setOnScreenChangeListener(new OnScreenChangeListener() {
- publicvoid onScreenChange(int currentIndex) {
- // TODO Auto-generated method stub
- generatePageControl(currentIndex);
- }
- });
- }
- public PageControlView(Context context) {
- super(context);
- this.init(context);
- }
- public PageControlView(Context context, AttributeSet attrs) {
- super(context, attrs);
- this.init(context);
- }
- privatevoid init(Context context) {
- this.context=context;
- }
- privatevoid generatePageControl(int currentIndex) {
- this.removeAllViews();
- int pageNum = 6; // 顯示多少個
- int pageNo = currentIndex+1; //第幾頁
- int pageSum = this.count; //總共多少頁
- if(pageSum>1){
- int currentNum = (pageNo % pageNum == 0 ? (pageNo / pageNum) - 1
- : (int) (pageNo / pageNum))
- * pageNum;
- if (currentNum < 0)
- currentNum = 0;
- if (pageNo > pageNum){
- ImageView imageView = new ImageView(context);
- imageView.setImageResource(R.drawable.zuo);
- this.addView(imageView);
- }
- for (int i = 0; i < pageNum; i++) {
- if ((currentNum + i + 1) > pageSum || pageSum < 2)
- break;
- ImageView imageView = new ImageView(context);
- if(currentNum + i + 1 == pageNo){
- imageView.setImageResource(R.drawable.page_indicator_focused);
- }else{
- imageView.setImageResource(R.drawable.page_indicator);
- }
- this.addView(imageView);
- }
- if (pageSum > (currentNum + pageNum)) {
- ImageView imageView = new ImageView(context);
- imageView.setImageResource(R.drawable.you);
- this.addView(imageView);
- }
- }
- }
- }
Java程式碼
- package cn.anycall.ju;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.MotionEvent;
- import android.view.VelocityTracker;
- import android.view.View;
- import android.view.ViewConfiguration;
- import android.view.ViewGroup;
- import android.widget.Scroller;
- /**
- * 仿Launcher中的WorkSapce,可以左右滑動切換螢幕的類
- *
- */
- publicclass ScrollLayout extends ViewGroup {
- privatestaticfinal String TAG = "ScrollLayout";
- private Scroller mScroller;
- private VelocityTracker mVelocityTracker;
- privateint mCurScreen;
- privateint mDefaultScreen = 0;
- privatestaticfinalint TOUCH_STATE_REST = 0;
- privatestaticfinalint TOUCH_STATE_SCROLLING = 1;
- privatestaticfinalint SNAP_VELOCITY = 600;
- privateint mTouchState = TOUCH_STATE_REST;
- privateint mTouchSlop;
- privatefloat mLastMotionX;
- privatefloat mLastMotionY;
- privateint currentScreenIndex = 0;
- publicint getCurrentScreenIndex() {
- return currentScreenIndex;
- }
- publicvoid setCurrentScreenIndex(int currentScreenIndex) {
- this.currentScreenIndex = currentScreenIndex;
- }
- public ScrollLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- // TODO Auto-generated constructor stub
- }
- public ScrollLayout(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- // TODO Auto-generated constructor stub
- mScroller = new Scroller(context);
- mCurScreen = mDefaultScreen;
- mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
- }
- @Override
- protectedvoid onLayout(boolean changed, int l, int t, int r, int b) {
- // TODO Auto-generated method stub
- int childLeft = 0;
- finalint childCount = getChildCount();
- System.out.println("childCount=" + childCount);
- for (int i = 0; i < childCount; i++) {
- final View childView = getChildAt(i);
- if (childView.getVisibility() != View.GONE) {
- finalint childWidth = childView.getMeasuredWidth();
- childView.layout(childLeft, 0, childLeft + childWidth,
- childView.getMeasuredHeight());
- childLeft += childWidth;
- }
- }
- }
- @Override
- protectedvoid onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- Log.e(TAG, "onMeasure");
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- finalint width = MeasureSpec.getSize(widthMeasureSpec);
- finalint widthMode = MeasureSpec.getMode(widthMeasureSpec);
- if (widthMode != MeasureSpec.EXACTLY) {
- thrownew IllegalStateException(
- "ScrollLayout only canmCurScreen run at EXACTLY mode!");
- }
- finalint heightMode = MeasureSpec.getMode(heightMeasureSpec);
- if (heightMode != MeasureSpec.EXACTLY) {
- thrownew IllegalStateException(
- "ScrollLayout only can run at EXACTLY mode!");
- }
- // The children are given the same width and height as the scrollLayout
- finalint count = getChildCount();
- for (int i = 0; i < count; i++) {
- getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
- }
- System.out.println("moving to screen " + mCurScreen);
- scrollTo(mCurScreen * width, 0);
- }
- /**
- * According to the position of current layout scroll to the destination
- * page.
- */
- publicvoid snapToDestination() {
- finalint screenWidth = getWidth();
- finalint destScreen = (getScrollX() + screenWidth / 2) / screenWidth;
- snapToScreen(destScreen);
- }
- publicvoid snapToScreen(int whichScreen) {
- // get the valid layout page
- whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
- if (getScrollX() != (whichScreen * getWidth())) {
- finalint delta = whichScreen * getWidth() - getScrollX();
- mScroller.startScroll(getScrollX(), 0, delta, 0,
- Math.abs(delta) * 2);
- mCurScreen = whichScreen;
- invalidate(); // Redraw the layout
- }
- }
- publicvoid setToScreen(int whichScreen) {
- whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
- mCurScreen = whichScreen;
- scrollTo(whichScreen * getWidth(), 0);
- }
- publicint getCurScreen() {
- return mCurScreen;
- }
- @Override
- publicvoid computeScroll() {
- // TODO Auto-generated method stub
- if (mScroller.computeScrollOffset()) {
- scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
- postInvalidate();
- }
- }
- @Override
- publicboolean onTouchEvent(MotionEvent event) {
- // TODO Auto-generated method stub
- if (mVelocityTracker == null) {
- mVelocityTracker = VelocityTracker.obtain();
- }
- mVelocityTracker.addMovement(event);
- finalint action = event.getAction();
- finalfloat x = event.getX();
- finalfloat y = event.getY();
- switch (action) {
- case MotionEvent.ACTION_DOWN:
- Log.e(TAG, "event down!");
- if (!mScroller.isFinished()) {
- mScroller.abortAnimation();
- }
- mLastMotionX = x;
- break;
- case MotionEvent.ACTION_MOVE:
- int deltaX = (int) (mLastMotionX - x);
- mLastMotionX = x;
- scrollBy(deltaX, 0);
- break;
- case MotionEvent.ACTION_UP:
- Log.e(TAG, "event : up");
- // if (mTouchState == TOUCH_STATE_SCROLLING) {
- final VelocityTracker velocityTracker = mVelocityTracker;
- velocityTracker.computeCurrentVelocity(1000);
- int velocityX = (int) velocityTracker.getXVelocity();
- Log.e(TAG, "velocityX:" + velocityX);
- if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {
- // Fling enough to move left
- Log.e(TAG, "snap left");
- onScreenChangeListener.onScreenChange(mCurScreen - 1);
- System.out.println("mCurScreen=" + (mCurScreen - 1));
- snapToScreen(mCurScreen - 1);
- } elseif (velocityX < -SNAP_VELOCITY
- && mCurScreen < getChildCount() - 1) {
- // Fling enough to move right
- Log.e(TAG, "snap right");
- onScreenChangeListener.onScreenChange(mCurScreen + 1);
- //只往右移動才載入資料
- onScreenChangeListenerDataLoad.onScreenChange(mCurScreen+1);
- snapToScreen(mCurScreen + 1);
- } else {
- snapToDestination();
- }
- if (mVelocityTracker != null) {
- mVelocityTracker.recycle();
- mVelocityTracker = null;
- }
- // }
- mTouchState = TOUCH_STATE_REST;
- break;
- case MotionEvent.ACTION_CANCEL:
- mTouchState = TOUCH_STATE_REST;
- break;
- }
- returntrue;
- }
- @Override
- publicboolean onInterceptTouchEvent(MotionEvent ev) {
- // TODO Auto-generated method stub
- Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop);
- finalint action = ev.getAction();
- if ((action == MotionEvent.ACTION_MOVE)
- && (mTouchState != TOUCH_STATE_REST)) {
- returntrue;
- }
- finalfloat x = ev.getX();
- finalfloat y = ev.getY();
- switch (action) {
- case MotionEvent.ACTION_MOVE:
- finalint xDiff = (int) Math.abs(mLastMotionX - x);
- if (xDiff > mTouchSlop) {
- mTouchState = TOUCH_STATE_SCROLLING;
- }
- break;
- case MotionEvent.ACTION_DOWN:
- mLastMotionX = x;
- mLastMotionY = y;
- mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST
- : TOUCH_STATE_SCROLLING;
- break;
- case MotionEvent.ACTION_CANCEL:
- case MotionEvent.ACTION_UP:
- mTouchState = TOUCH_STATE_REST;
- break;
- }
- return mTouchState != TOUCH_STATE_REST;
- }
- //分頁監聽
- publicinterface OnScreenChangeListener {
- void onScreenChange(int currentIndex);
- }
- private OnScreenChangeListener onScreenChangeListener;
- publicvoid setOnScreenChangeListener(
- OnScreenChangeListener onScreenChangeListener) {
- this.onScreenChangeListener = onScreenChangeListener;
- }
- //動態資料監聽
- publicinterface OnScreenChangeListenerDataLoad {
- void onScreenChange(int currentIndex);
- }
- private OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad;
- publicvoid setOnScreenChangeListenerDataLoad(OnScreenChangeListenerDataLoad onScreenChangeListenerDataLoad) {
- this.onScreenChangeListenerDataLoad = onScreenChangeListenerDataLoad;
- }
- }
main.xml
Xml程式碼
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextViewandroid:layout_width="fill_parent"
- android:layout_height="wrap_content"android:text="仿淘寶聚划算"/>
- <RelativeLayout
- android:id="@+id/myView"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <cn.anycall.ju.ScrollLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/ScrollLayoutTest"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"android:background="#000000">
- </cn.anycall.ju.ScrollLayout>
- <cn.anycall.ju.PageControlView
- android:id="@+id/pageControl"
- android:layout_width="fill_parent"
- android:layout_height="40px"
- android:background="#8f00000f"
- android:layout_alignParentBottom="true"
- android:gravity="center"/>
- </RelativeLayout>
- </LinearLayout>
app_item.xml
Xml程式碼
- <?xmlversion="1.0"
相關推薦
Android GridView 分頁載入資料
android UI 往右滑動,滑動到最後一頁就自動載入資料並顯示 如圖: Java程式碼 package cn.anycall.ju; import java.util.ArrayList; import
面試問題之:Android中ListView分頁載入資料
熟悉Android的朋友們都知道,不管是微部落格戶端還是新聞客戶端,都離不開列表元件,可以說列表元件是Android資料展現方面最重要的元件,我們今天就要講一講列表元件ListView載入資料的相關內容。通常來說,一個應用在展現大量資料時,不會將全部的可用資料都呈現給
android ListView 動態分頁載入資料
用ListView顯示資料時,列表中資料量大時,載入和處理時間會明顯變長,如果等到把所有資料都處理載入完成再顯示出來,那程式的UI就非常糟糕了,很可能會隨資料量的變大而變慢,這樣的介面很不友好,我們無法接受。 廢話說完了,那怎麼解決這個的問題呢? 動態載入,分頁載
Android裡ListView分頁載入資料
當列表資料量大的時候我們一半都進行分頁,android裡分頁一半不同於PC端,第幾頁的方式,一般都是滑動到底部資料自帶載入,廢話不多數了直接看程式碼: ListActivity.java類: import java.util.ArrayList; import an
android中listview分頁載入資料
前段時間做的新浪微博專案一直想實現listview分頁載入資料,今天終於實現了,哈哈!感覺挺好的,今天又寫了個demo給大家分享下。 首先說下listview的優化方案,這也是面試中常考的題目。優化方案有三種:1,如
【小程式】分頁載入資料,下拉載入更多,上拉重新整理
【 小程式】分頁載入資料,下拉載入更多,上拉重新整理 分頁載入的優點就不多說了,下面主要記錄一下幾個問題點。 scroll-view元件不能用在頁面根佈局中,不然觸發不了系統的onPullDownRefresh()、onReachBottom()回撥。 在Page頁
小程式分頁載入資料
(({ data }) => { if (data.object && data.object.list && data.object.list.length) { let list = data.object.list; fo
android ListView分頁載入
package com.example.administrator.datapageload; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; imp
listview實現分頁載入資料的注意點
/** * 未讀資訊list */ public class MessageSecondLayerActivity extends Activity implements View.OnClickListener { private ListView listView; private L
微信小程式分頁載入資料
在使用類似qq,微博或者新聞類等資料量大的應用經常會遇到分頁載入功能,它不僅的應用場景廣,還能挺高使用者體驗。微信小程式中也可以分頁載入資料,這篇文章就是介紹。要實現這樣的功能,一般需要在請求資料時加入當前請求頁數,以及頁的大小(每頁顯示的數量)也有一部分介面是通過請求的開始
Adapter之大資料滑動效率優化和分頁載入資料
在Android中如果要做到大資料分頁載入則需要我們的Activity實現OnScrollListener滾動條監聽介面。當如果要做的更加高大上。比如需要在使用者滑動至列表的底部,觸碰摸個區域,則需要實現OnTouchListener介面,等等。
微信小程式ajax請求分頁載入資料
分頁載入功能大家遇到的應該會經常遇到,應用場景也很多,例如微博,QQ,微信朋友圈以及新聞類應用,都會有分頁載入的功能,這不僅節省了我們使用者的流量,還提升了使用者體驗。那麼今天的這篇文章就是介紹微信小程式中如何實現分頁載入的功能。照例先上原始碼及效果圖。原始碼傳送門要實現這樣的功能,一般需要在請求資料時加入當
js滾動分頁載入資料
實現理念: 1.判斷滾動條到底部觸發載入函式 2.請求資料 3.追加資料 html: <div class="list_flex" id="listrow"> <a href="./index.php?i=3&c=entry&m=ewei_
ANDROID GridView 分頁平滑滑動 效果的實現(基於android TV遙控器操作)
1.android 使用GridView 實現載入大量的資料顯示。未顯示出來的資料可以滑動螢幕讓底部的資料顯示出來,但是原生態的GridView 並沒有很美觀平滑的一個動畫來滾動資料,因此,我們可以稍做修改就可以實現 類似VST全聚合裡面 視訊載入也那樣的翻頁動畫效果了。
jquery 滾動條分頁載入資料
廢話不多說 直接擼 1.引入兩個js檔案,必須jquery第一個 <script src="jquery.min.js"/> <script src="jquery.infinit
手機端滾動分頁載入資料模型
說明:執行demo的時候請將瀏覽器模式調整到蘋果5 <!DOCTYPE html> <html lang="en"> <head> <meta
Android自定義控制元件(一) 下拉重新整理,上拉分頁載入更多(支援ListView, GridView, ScrollView)
首先說明,這幾篇文章是對一些前輩的成果進行學習後的心得總結。也借這種方式對他們表示謝意。 最近專案中好幾個模組都用到listview和gridview的下拉重新整理,上拉載入更多等功能,而且涉及到圖片的批量下載。水平有限,首先是想到找一些比較
ListView分頁載入,動態從網上拉取資料
最近做專案有個需求: (1)從網上獲取分頁資料; (2)在Android手機端顯示; (3)載入的動畫和文字; (4)資料超過40條時顯示滑動條等。 由於之前自己做的偏底層一點,所以這塊內容琢磨了蠻久,最後可以完美實現專案需求,內容見下面: 一、首先,需要有個佈局
ListView 分頁載入網路資料
1.分頁載入思路 (1)判斷是否滑動到底部 (2)當滑動到底部,往資料來源中新增資料,然後呼叫adapter.notifyDataSetChanged()方法重新整理顯示的listView資料。 2. 下面是糗事百科載入的例項,載入效果如下(為了顯示效
listView下拉重新整理,分頁載入(無更多資料時新增底線)
package com.example.yjyg.mytourismnote.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.suppo