的ViewPage解决方案 [英] ViewPage solution

查看:130
本文介绍了的ViewPage解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序很少活动和一些布局.. 应该有100页,了解scienze,自然多,但我不想做100的布局我想不同的网页添加到我的看法适配器,你会与一个列表。使用相同的布局和所有只是新数据添加到它(如列表)。我想创建一个相同的列表视图的概念,但不同的DATAS页......已经有一个什么,我说什么职位:的在我的应用使用viewpager但我无法理解如何做到这一点.. 我做了一些尝试。我把Android的支持,v4.jar在库..我所做的xml文件:

I want to have few activities and few layouts in my application.. There should be 100 pages to read about scienze,nature and more but i dont want to make 100 layouts I want to add different pages to my view adapter as you would with a list. use the same layout for all and just add new data to it (like a list). I want to create pages with same listview concept but different datas.. There is already a post about what i am talking about: Using viewpager in my application but i cant understand how to do it.. I did some attempts.. i put the android-support-v4.jar in libs.. i made the xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="vertical"

 >
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1" >
</android.support.v4.view.ViewPager>

</LinearLayout>

至极是下一步??

Wich is the next step??

推荐答案

随着奥列格的答案,我想补充<一href="http://wptrafficanalyzer.in/blog/implementing-horizontal-view-swiping-using-viewpager-and-fragmentpageradapter-in-android/"相对=nofollow>这个简单的教程,我发现有源$ C ​​$ C,你可以下载,一旦是为你工作,你可以慢慢的,你了解它是如何工作使其适应您的需求。这表明如何显示的TextView 我相信这是你想要的,而不是一个图片什么。一旦你从已获得的链接之一的基本下跌,我想你可能要创建一个的ArrayList (可能在自己的类),并从数据有添加到,由于每个页面的的TextView 到大量的,你计划有网页。如果你把你的时间,并确保你理解这些组件是如何协同工作的基础知识,然后我想休息会更容易为你。

Along with Oleg's answer I would add this simple tutorial which I found that has source code you can download and, once that is working for you, you can adapt it to your needs slowly as you learn how it works. This shows how to display a TextView which I believe is what you want instead of an Image. Once you get the basics down from one of the links you have been given, I think you may want to create an ArrayList (possibly in its own class) and get the data from there to add to each page's TextView due to the large number of pages that you plan on having. If you take your time and make sure you understand the basics of how these components work together then I think the rest will come easier for you.

我同意奥列格的答案,你可能要使用 FragmentStatePagerAdapter ,因为大量的页/数据,你就会有。但是,给这个教程的一个镜头,看看是否可以帮助您如何将这些所有的工作的感觉在一起。祝你好运!

I agree with Oleg's answer that you probably want to use a FragmentStatePagerAdapter because of the large amount of pages/data you will have. But give this tutorial a shot and see if that helps you make sense of how these all work together. Good Luck!

更新

由于我没有这样做之前,我会给我最好的拍摄,以显示你的东西可能会奏效。如果没有玩弄我自己,我不能肯定地说,但我会给这是一个尝试(使用code从turorial和由类返回一个数组)

As I haven't done this before I will give my best shot to show you something that might work. Without playing around with it myself, I can't say for sure but I would give this a try (using the code from the turorial and a made up class that returns an array)

 public Fragment getItem(int arg0) {
    MyFragment myFragment = new MyFragment();
    Bundle data = new Bundle();
    String myArrayString = new ArrayClassName().getText(arg0);  //This should get a string value from a method you create in your Array class called getText()
    data.putInt("current_page", arg0);
    myFragment.setArguments(data);
    return myFragment;  //this hopefully gets passed back to onCreateView()
}

然后使用的setText(mCurrentPage),因为他们在做 onCreateView()设置页面的文本。我可能已经错过了一些东西,因为我没有在我的脑海所有这一切,但我会想象这样的事情会得到你开始。希望它的工作原理,因为这是一个整体大量的工作不是用本品前:D

Then use setText(mCurrentPage) as they did in the onCreateView() to set the page text. I may have missed something since I did all of this in my head but I would imagine something like this would get you started. Hopefully it works because that was a whole lot of work not using this before :D

这篇关于的ViewPage解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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