Android实现滑动加载数据的方法

Android实现滑动加载数据的方法,第1张

概述本文实例讲述了Android实现滑动加载数据的方法。分享给大家供大家参考。具体实现方法如下:

本文实例讲述了AndroID实现滑动加载数据的方法。分享给大家供大家参考。具体实现方法如下:

EndLessActivity.java如下:

package com.ScrollListVIEw;import AndroID.app.ListActivity;import AndroID.os.Bundle;import AndroID.vIEw.Gravity;import AndroID.vIEw.VIEw;import AndroID.vIEw.VIEwGroup;import AndroID.Widget.AbsListVIEw;import AndroID.Widget.BaseAdapter;import AndroID.Widget.linearLayout;import AndroID.Widget.Progressbar;import AndroID.Widget.TextVIEw;import AndroID.Widget.AbsListVIEw.OnScrollListener;public class EndLessActivity extends ListActivity implements OnScrollListener { aleph0 adapter = new aleph0();  int mProgressstatus = 0 ; Progressbar progressbar;  protected voID onCreate(Bundle savedInstanceState) {   super .onCreate(savedInstanceState);  linearLayout searchLayout = new linearLayout( this );  searchLayout.setorIEntation(linearLayout.HORIZONTAL);    progressbar = new Progressbar( this );    progressbar.setpadding( 0,15,0 );    searchLayout.addVIEw(progressbar,new linearLayout.LayoutParams(    linearLayout.LayoutParams.WRAP_CONTENT,linearLayout.LayoutParams.WRAP_CONTENT    ));    TextVIEw textVIEw = new TextVIEw( this );    textVIEw.setText( " 加载中... " );    textVIEw.setGravity(Gravity.CENTER_VERTICAL);    searchLayout.addVIEw(textVIEw,new linearLayout.LayoutParams(    linearLayout.LayoutParams.FILL_PARENT,linearLayout.LayoutParams.FILL_PARENT    ));    searchLayout.setGravity(Gravity.CENTER);    linearLayout loadingLayout = new linearLayout( this );    loadingLayout.addVIEw(searchLayout,linearLayout.LayoutParams.WRAP_CONTENT    ));    loadingLayout.setGravity(Gravity.CENTER);    getListVIEw().addFooterVIEw(loadingLayout);  setlistadapter(adapter);   getListVIEw().setonScrollListener( this ); }  public voID onScroll(AbsListVIEw vIEw,int firstVisible,int visibleCount,int totalCount) {   boolean loadMore = /* maybe add a padding */   firstVisible + visibleCount >= totalCount;   if (loadMore) {   adapter.count += visibleCount; // or any other amount    adapter.notifyDataSetChanged();  } }  public voID onScrollStateChanged(AbsListVIEw v,int s) { }   class aleph0 extends BaseAdapter {   int count = 40 ; /* starting amount */   public int getCount() { return count; }   public Object getItem( int pos) { return pos; }   public long getItemID( int pos) { return pos; }   public VIEw getVIEw( int pos,VIEw v,VIEwGroup p) {    TextVIEw vIEw = new TextVIEw(EndLessActivity. this );    vIEw.setText( " entry " + pos);     return vIEw;  } }}

ListvIEw下部是按钮控制:

package com.ScrollListVIEw;import AndroID.app.ListActivity;import AndroID.os.Bundle;import AndroID.vIEw.Gravity;import AndroID.vIEw.VIEw;import AndroID.vIEw.VIEwGroup;import AndroID.Widget.AbsListVIEw;import AndroID.Widget.BaseAdapter;import AndroID.Widget.button;import AndroID.Widget.linearLayout;import AndroID.Widget.Progressbar;import AndroID.Widget.TextVIEw;import AndroID.Widget.AbsListVIEw.OnScrollListener;public class EndLessActivity extends ListActivity { aleph0 adapter = new aleph0();  int mProgressstatus = 0 ;  protected voID onCreate(Bundle savedInstanceState) {   super .onCreate(savedInstanceState);  linearLayout searchLayout = new linearLayout( this );  searchLayout.setorIEntation(linearLayout.HORIZONTAL);    button textVIEw = new button( this );    textVIEw.setText( " 加载中... " );    textVIEw.setGravity(Gravity.CENTER_VERTICAL);    searchLayout.addVIEw(textVIEw,linearLayout.LayoutParams.WRAP_CONTENT    ));    loadingLayout.setGravity(Gravity.CENTER);    getListVIEw().addFooterVIEw(loadingLayout);    textVIEw.setonClickListener( new button.OnClickListener()    {  @OverrIDe      public voID onClick(VIEw v)     {       adapter.count += 10 ;      adapter.notifyDataSetChanged();     }      });   setlistadapter(adapter);    // getListVIEw().setonScrollListener(this);  } /* public voID onScroll(AbsListVIEw vIEw,int totalCount) {  boolean loadMore =    firstVisible + visibleCount >= totalCount;  if(loadMore) {   adapter.count += visibleCount;    adapter.notifyDataSetChanged();  } } */  public voID onScrollStateChanged(AbsListVIEw v,VIEwGroup p) {    TextVIEw vIEw = new TextVIEw(EndLessActivity. this );    vIEw.setText( " entry " + pos);     return vIEw;  } }}

希望本文所述对大家的AndroID程序设计有所帮助。

总结

以上是内存溢出为你收集整理的Android实现滑动加载数据的方法全部内容,希望文章能够帮你解决Android实现滑动加载数据的方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1142311.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存