时间:2021-05-02
本文实例讲述了Android实现滑动加载数据的方法。分享给大家供大家参考。具体实现方法如下:
EndLessActivity.java如下:
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 = 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 ; 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下部是按钮控制:
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 onScrollStateChanged(AbsListView v, int s) { } class Aleph0 extends BaseAdapter { int count = 40 ; 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; } } }希望本文所述对大家的Android程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了Android实现基于滑动的SQLite数据分页加载技术。分享给大家供大家参考,具体如下:main.xml如下:MainActivity.java
本文实例为大家分享了Android实现View滑动的具体方法,供大家参考,具体内容如下1.View的滑动简介View的滑动是Android实现自定义控件的基础,
本文实例讲述了Android滑动动态分页实现方法。分享给大家供大家参考,具体如下:实现Android.widget.AbsListView.OnScrollLi
实现Android滑动退出Activity的功能android向右滑动,退出activity//右滑删除compile'com.jude:swipebackhe
Android开发仿IOS滑动开关实现代码Android与iOS相比,ios好多控件都是自带的,而android需要使用自定义来实现。今天说的是ios的滑动开关