简体   繁体   English

将Android ListView显示为页面

[英]Display Android ListView as pages

I have a listview where I'm displaying items as pages with 3 items per page. 我有一个列表视图,其中我将项目显示为页面,每页3个项目。 Depending on user clicking prev or next buttons I am scrolling through the listview using setSelection . 根据用户单击上一个或下一个按钮的方式,我将使用setSelection在列表视图中滚动。 Here is the code: 这是代码:

int size = listView.getCount(); 
int scrollToPosition = 0;
if(direction == PREV)
    scrollToPosition = listView.getFirstVisiblePosition() - 3;
else
    scrollToPosition = listView.getFirstVisiblePosition() + 3;
if(scrollToPosition < 0) { scrollToPosition = 0; }
else if (scrollToPosition >= size) { scrollToPosition = size - 1; } 
listView.setSelection(scrollToPosition);

With this approach, if I have 4 items in the list, the first page shows items 1,2,3 and page 2 shows items 2,3,4. 使用这种方法,如果列表中有4个项目,则第一页显示项目1,2,3,而第二页显示项目2,3,4。 I need to change this such that page 1 shows 1,2,3 and page 2 shows only the 4th item. 我需要更改此设置,以使第1页显示1,2,3,第2页仅显示第4个项目。 How do I change this? 我该如何改变?

您必须为不同的页面制作不同的元素数组。例如arr1应该包含元素1,2,3和arr2应该包含4并填充页面1的arr1和页面2的arr2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM