最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)滑動(dòng)加載數(shù)據(jù)的方法

 更新時(shí)間:2015年07月21日 17:27:45   作者:華宰  
這篇文章主要介紹了Android實(shí)現(xiàn)滑動(dòng)加載數(shù)據(jù)的方法,實(shí)例分析了Android通過(guò)滑動(dòng)實(shí)現(xiàn)動(dòng)態(tài)加載數(shù)據(jù)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android實(shí)現(xiàn)滑動(dòng)加載數(shù)據(jù)的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

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 , 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, new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.WRAP_CONTENT,
    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, new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.FILL_PARENT,
    LinearLayout.LayoutParams.FILL_PARENT
    ));
    searchLayout.setGravity(Gravity.CENTER);
    LinearLayout loadingLayout = new LinearLayout( this );
    loadingLayout.addView(searchLayout, new LinearLayout.LayoutParams(
    LinearLayout.LayoutParams.WRAP_CONTENT,
    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 firstVisible, int visibleCount, int totalCount) {
  boolean loadMore = 
   firstVisible + visibleCount >= totalCount;
  if(loadMore) {
   adapter.count += visibleCount; 
   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;
  }
 }
}

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

大姚县| 应用必备| 定襄县| 建昌县| 富宁县| 绥芬河市| 彭泽县| 陆河县| 凤冈县| 衡东县| 慈利县| 永修县| 松江区| 瑞丽市| 兴隆县| 双江| 泸西县| 镶黄旗| 如东县| 辰溪县| 根河市| 濉溪县| 萨嘎县| 八宿县| 嘉鱼县| 辉南县| 平和县| 宝兴县| 年辖:市辖区| 涞源县| 肃宁县| 永定县| 巨鹿县| 阿拉善右旗| 孟村| 新民市| 鄢陵县| 什邡市| 比如县| 赤城县| 巴塘县|