如何限制由10和明年10after单击下一步按钮的ListView列表项显示 [英] How to limit list items display in ListView by 10 and next 10after clicking next button

查看:117
本文介绍了如何限制由10和明年10after单击下一步按钮的ListView列表项显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有100项的列表视图,我想显示前10个项目,并单击下一步按钮,我必须展示未来10即11日至20日,我有$ C $下得到的前10项

i have a listview with 100 items and i want to display first 10 items and on click of next button i have to display next 10 ie.,from 11 to 20, i have the code for getting first 10 items

public int getCount() {
        return 10;
    }

但如何获得10项单独等下一次。 任何想法

but how to get next 10 items alone and so on. any idea

推荐答案

要做到这一点的方法之一是,

One way to do this is,

1)不要所有的数据填充的ArrayList。相反,让他们在一个单独的ArrayList( AL1 ),并使用ArrayList(<$ C C $> AL2 ),最大10个值与使用你BaseAdapter。

1) Don't populate your ArrayList with all the data. Instead keep them in a separate ArrayList (al1) and use an ArrayList (al2) with max 10 values to use with your BaseAdapter.

2)开始,

  • AL2 = AL1 [0]到AL1 [9]
  • BaseAdatper(背景下,数据)

3)保持BaseAdapter,因为它是,但更改

3) Keep the BaseAdapter as it is but change

 @Override
 public int getCount() {
 return 10;
}

 @Override
 public int getCount() {
 return data.size();
}

这不是必须的,但它是很好的做法。现在,你将只显示10个项目造成这一切要传递到适配器。此外,在您的扩展BaseAdatper类设置数据写入一个公共职能变量。

4)单击Next按钮事件得到下一个10个项目,从 AL1 ,并分配给 AL2 。使用你在写写信给公共职能数据 AL2

4) On the next button click event get the next 10 items from al1 and assign to al2. Use the public function you wrote to over write data with al2.

5)<一href="https://developer.android.com/reference/android/widget/BaseAdapter.html#notifyDataSetChanged%28%29"相对=nofollow> BaseAdapter有一个叫做notifyDataSetChanged 方法,调用它。这样做是告诉适配器刷新从上到下。既然你有数据在写入新数据时,刷新时,你会看到新的数据。就是这样。

5) BaseAdapter has a method called notifyDataSetChanged , call it. What this does is tell the adapter to refresh from top to bottom. Since you have data over written with new data when the refresh occurs you'll be seeing the new data. That's it.

我不认为这将是你很难想出一个方法来跟踪从哪个指标来这 AL1 您当前正在显示。 :)

I don't think it'll be difficult for you to come up with a way to keep track from which index to which in al1 you're currently displaying. :)

这篇关于如何限制由10和明年10after单击下一步按钮的ListView列表项显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆