0

我已经尝试了很多教程,但我在Android上有点新,所以这是我的问题。我需要一个导航抽屉的片段内的Viewpager。

我有一个抽屉布局MainActivity和片段A,B,C和D.
在片段C我有我的布局,像textViews,imageViews和我需要添加像iOS设备上的viewPager。 问题在于每个教程和这里回答的问题都表示要在活动上启动PageAdapter,但我需要在Fragment上使用它,因为它是我拥有填充C片段信息的信息的位置。
应该出现的视图寻呼机,只包含一个textView,它填充了一个web服务请求,我得到的消息放在textView上,这就是为什么我需要在碎片C上使用这个。所以这里是我的pageAdapter:使用viewPager与片段android?

public class PageAdapter extends FragmentPagerAdapter { 
private String message; 

public PageAdapter(FragmentManager fm , String message) { 
    super(fm); 
    this.message = message; 

} 

/** 
* Get fragment corresponding to a specific position. This will be used to populate the 
* contents of the view pager 
* 
* @param position Position to fetch fragment for. 
* @return Fragment for specified position. 
*/ 
@Override 
public Fragment getItem(int position) { 
    // getItem is called to instantiate the fragment for the given page. 

    Fragment fragment = new PageVestiarioFragment(); 
    Bundle args = new Bundle(); 
    args.putString("message", message); 
    fragment.setArguments(args); 
    return fragment; 
} 

/** 
* Get number of pages the should render. 
* 
* @return Number of fragments to be rendered as pages. 
*/ 
@Override 
public int getCount() { 
    // Show 3 total pages. 
    return 3; 
} 
} 

这是我pageViewer项目:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="center_horizontal" 
android:id="@+id/pageViewLayout" 
tools:context="com.example.mobirama.golaco.VestiarioFragment"> 

<TextView 
    android:id="@+id/message_TextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Mensagem recebida via rest" 
    android:textSize="20sp" 
    android:textColor="@color/text_green" /> 
    </RelativeLayout> 

这是我的C片段布局,只要有太多的信息,我把刚才那块地方有综合浏览量(这在一个relativeLayout里面)

<HorizontalScrollView 
      android:id="@+id/messages_ScrollView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" > 

      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal"> 

       <android.support.v4.view.ViewPager 
        android:id="@+id/pager" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

      </RelativeLayout> 

     </HorizontalScrollView> 

只是一块,我设置的信息

for (Integer i = 0; i < messages.length; i++) { 
      if (messages[i] != null) { 
       items.add(messages[i]); 
       mAdapter = new PageAdapter(getChildFragmentManager() , messages[i].getMessage()); 
       pager.setAdapter(mAdapter); 
      } 
     } 

的问题是机器人工作室的显示了这个消息:android.support.v4.app.fragmentmanager不匹配android.support.app。 fragmentmanager

我试图改变支持v13,但没有奏效。

有人可以帮助我吗?

+0

看看这个应用程序:https://github.com/Dahnark/Material-Design-Tabs,它是一个应用程序显示片段内的标签。您可以在抽屉内添加FrameLayout。 – Dahnark 2015-02-11 00:33:39

回答

0

您定位的是哪个兼容级别?你需要让一切比赛:

  • FragmentPagerAdapter
  • 您的片段的对象,尤其是片段C

从你的XML()我可以看到你的目标V4,所以你可能要改变一切到v4。

+0

当一切都与v4我有compability的问题:android.support.v4.app.fragmentmanager不符合android.support.app.fragmentmanager – Juliana 2015-02-10 23:25:14

+0

这个错误发生在哪里? android.support.app.fragmentmanager的实例在哪里?如果您的片段调用getChildFragmentManager()是来自v4支持库的Fragment实例应该可以正常工作。 – Quanturium 2015-02-10 23:31:01

+0

兼容性的问题解决了我使用v13,但它仍然不显示布局 – Juliana 2015-02-15 17:15:46