问题描述
我有延伸ActionBarActivity和活动活动有以下的XML code。
I have an Activity which extends ActionBarActivity and activity has following code in xml.
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
它只有ViewPager。我想显示与选项列表的图像,所以我选择了创建具有布局的片段我想显示为ViewPager的一部分。
It has just ViewPager. I want to display Image with list of options so I opted for creating a fragment with layout I want to be shown as a part of ViewPager.
我创建扩展FragmentPagerAdapter适配器如下:
I created an adapter extending FragmentPagerAdapter as follows:
私有类CategoryViewPagerAdapter扩展FragmentStatePagerAdapter {
private class CategoryViewPagerAdapter extends FragmentStatePagerAdapter {
public CategoryViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int currentPosition) {
return FullScreenFragment.newInstance(fragments
.get(currentPosition));
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return fragments.size();
}
}
在哪里片段是一个字符串列表。
Where fragments is list of Strings.
它加载图像和图像但也狂击所示的工作有标题是previous形象。
这个称号是在动作条基本设置该片段。
It loads Images and Swipes also work however Image shown has title which is of previous image.THis title is basically set in ActionBar for that fragment.
在我的片段类我这样做:
In my fragment class I did this:
parentActivity = (ActionBarActivity) getActivity();
parentActivity.getSupportActionBar().setDisplayOptions(
ActionBar.DISPLAY_SHOW_CUSTOM);
parentActivity.getSupportActionBar().setCustomView(
R.layout.full_screen_action_bar);
和也与片段布局有时几个组件不渲染点击片段中的一个按钮。我需要从活动到findId或片段rootView
And also sometimes few components with in fragment layout dont rendered on click a button within fragment. Do i need to findId from Activity or Fragment rootView
推荐答案
使用此方法来更新操作栏
use this method to update action bar
vp.setOnPageChangeListener(new OnPageChangeListener()
{
@Override
public void onPageSelected(int arg0)
{
//update action bar
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0)
{
// TODO Auto-generated method stub
}
});
而对于第二个问题,请给更多的信息。
And for the second problem , please give more info .
这篇关于ViewPager与FragmentPageAdater不正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!