简体   繁体   English

在Android中实现View Pager

[英]Implementing View Pager in android

I have a problem that, I have to implement horizontal swipe view as a paging system and each page shows data from the server, means each page shows dynamic data at run time. 我有一个问题,我必须将水平滑动视图实现为分页系统,并且每个页面都显示来自服务器的数据,这意味着每个页面在运行时都显示动态数据。 I think it is possible with View Pager but in View Pager there is no any fixed layout which is shown on particular page, So, firstly how can we do that, secondly in View Pager all views should be predesigned or preimplemented or we can say that Number of Views we must know. 我认为可以使用View Pager,但是在View Pager中没有任何固定的布局显示在特定页面上,因此,首先,我们该怎么做,其次,在View Pager中,所有视图都应该预先设计或预先实现,或者我们可以说我们必须知道的视图数。 But when we want to take it dynamic when user swipe a page then it goes to next page but progressbar will appear to show the data for corresponding page. 但是,当我们要在用户滑动页面时使其动态时,它将转到下一页,但进度条将显示以显示相应页面的数据。 So, how can we do this also? 那么,我们又怎么做呢? Please suggest me any solution regarding the same. 请建议我任何与此有关的解决方案。

View Pager: 查看寻呼机:

View Pager Demo http://android-developers.blogspot.in/2011/08/horizontal-view-swiping-with-viewpager.html 查看分页器演示 http://android-developers.blogspot.in/2011/08/horizontal-view-swiping-with-viewpager.html

Thanks in advance. 提前致谢。

Have you tried to implement 您是否尝试实施

viewPager.setOnPageChangeListener(this);

to detect page changement and so loading the page content 检测页面更改并因此加载页面内容

The solution isn't in ViewPager but in your custom PagerAdapter. 解决方案不在ViewPager中,而是在您的自定义PagerAdapter中。 You must subclass the PagerAdapter and add a method to add content to your adapter and call in this method the method notifyDataSetChanged : 您必须继承PagerAdapter的子类,并添加一个方法以将内容添加到适配器中,并在此方法中调用方法notifyDataSetChanged:

public void addPage(Object page) {
    // Add page to the arraylist of adapter 
    notifyDataSetChanged();
}

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

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