安卓开发中,listview数量过多,加更多按钮显示
2014-04-01 14:24
218 查看
更多按钮的页面,如:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:orientation="horizontal"
>
<TextView
android:id="@+id/load_more_view_tv"
android:layout_width="200dp"
android:layout_height="30dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="18sp"
android:background="@color/sj_bg_blue"
android:textColor="@color/white"
android:text="更多"
android:textSize="20sp" />
<ProgressBar
android:id="@+id/load_more_view_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/load_more_tv"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
在要显示listview的activity中,有
View loadMoreView;
TextView loadMoreTextView;
ProgressBar loadMoreProgressBar;
private int currentCount = 1;
private int incrementCount = 5;
private ArrayList list;
LayoutInflater l = LayoutInflater.from(this);
loadMoreView = l.inflate(R.layout.load_more_view, null);
loadMoreTextView = (TextView) loadMoreView.findViewById(R.id.load_more_view_tv);
loadMoreProgressBar = (ProgressBar) loadMoreView.findViewById(R.id.load_more_view_progress);
下载listview的数据后,进行数据显示,如:
private void setListView(){
if (list.getFooterViewsCount() < 1) {
list.addFooterView(loadMoreView);//添加页脚(放在ListView最后)。该方法要求在setAdapter之前调用。
}
int newsSize = list.size();
if (currentCount >= newsSize) {
currentCount = newsSize;
showNoLoadMore();
} else {
showLoadMore();
}
loaded();
}
private void loaded(){
list.setAdapter(myAdapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
if (arg1.equals(loadMoreView)) {
loadMoreStart();
currentCount += incrementCount;
if (currentCount >= list.size()) {
myAdapter.setCount(list.size());
myAdapter.notifyDataSetChanged();
showNoLoadMore();
} else {
myAdapter.setCount(currentCount);
myAdapter.notifyDataSetChanged();
loadMoreEnd();
}
}else{
/////
}
}
});
}
这样就可以控制每次显示的数量,并加上更多按钮,点击时,会增加显示数据的数量
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:orientation="horizontal"
>
<TextView
android:id="@+id/load_more_view_tv"
android:layout_width="200dp"
android:layout_height="30dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="18sp"
android:background="@color/sj_bg_blue"
android:textColor="@color/white"
android:text="更多"
android:textSize="20sp" />
<ProgressBar
android:id="@+id/load_more_view_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/load_more_tv"
android:indeterminate="true"
android:visibility="invisible" />
</RelativeLayout>
在要显示listview的activity中,有
View loadMoreView;
TextView loadMoreTextView;
ProgressBar loadMoreProgressBar;
private int currentCount = 1;
private int incrementCount = 5;
private ArrayList list;
LayoutInflater l = LayoutInflater.from(this);
loadMoreView = l.inflate(R.layout.load_more_view, null);
loadMoreTextView = (TextView) loadMoreView.findViewById(R.id.load_more_view_tv);
loadMoreProgressBar = (ProgressBar) loadMoreView.findViewById(R.id.load_more_view_progress);
下载listview的数据后,进行数据显示,如:
private void setListView(){
if (list.getFooterViewsCount() < 1) {
list.addFooterView(loadMoreView);//添加页脚(放在ListView最后)。该方法要求在setAdapter之前调用。
}
int newsSize = list.size();
if (currentCount >= newsSize) {
currentCount = newsSize;
showNoLoadMore();
} else {
showLoadMore();
}
loaded();
}
private void loaded(){
list.setAdapter(myAdapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
if (arg1.equals(loadMoreView)) {
loadMoreStart();
currentCount += incrementCount;
if (currentCount >= list.size()) {
myAdapter.setCount(list.size());
myAdapter.notifyDataSetChanged();
showNoLoadMore();
} else {
myAdapter.setCount(currentCount);
myAdapter.notifyDataSetChanged();
loadMoreEnd();
}
}else{
/////
}
}
});
}
这样就可以控制每次显示的数量,并加上更多按钮,点击时,会增加显示数据的数量
相关文章推荐
- 安卓开发——问题:ScrollView中嵌套ListView时,listview只显示一行
- 基于安卓开发动态改变按钮的数量
- 安卓开发-ListView侧拉菜单,置顶等仿QQ侧拉菜单侧拉点击切换图片,侧拉点击事件带上拉加载更多,下拉刷新
- 安卓开发ListView列表点击显示错乱bug自我总结
- 开发第一个安卓程序(按钮显示一个当前的系统时间)
- 安卓开发之显示倒计时按钮控件
- 安卓开发(二)ListView显示菜单,SQLite存储和ListView显示
- Android基础 为listView增加更多按钮(分页显示)
- Android基础 为listView增加更多按钮(分页显示)
- android开发步步为营之43:listview的使用(下篇:显示图片和按钮)
- 两个并排的按钮只显示了一个【安卓开发布局问题 wrap_content】
- 【Android开发学习28】界面控件之列表控件(ListView)--显示字符数组
- 安卓开发--ListView
- [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
- ecshop二次开发——商品列表页显示重量、货号、购买数量
- 安卓开发 EditText 的多行显示设置
- 安卓开发-自己实现CursorAdapter将数据的数据装载到ListView
- AI开发实战7-列表显示框(Listview)的定制
- 魅蓝 安卓开发调试 无法显示连接解决
- iOS开发--底部按钮和应用图标显示未读消息