2 u010298576 u010298576 于 2014.09.26 22:59 提问

使用开源框架 TabPageIndicator 提示 ViewPager has not been bound

我想将网易新闻客户端的那个左右滑动切换页面的效果,加到我的项目中
下面是我的布局xml

<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F6F6F6"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/ll_indicator"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:background="@drawable/news_tab_bg"
    android:orientation="horizontal" >

    <com.example.abvc_helper.ui.pageindicator.TabPageIndicator
        android:id="@+id/indicator"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingBottom="2dp" />

    <ImageView
        android:id="@+id/iv_edit_cate"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:scaleType="center"
        android:src="@drawable/news_cate_arr" />
</LinearLayout>

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

下面是我的java部分代码
private ViewPager pager ;
private TabPageIndicator indicator;

adapter = new TabPageIndicatorAdapter(pages);
pager.removeAllViews();
pager.setAdapter(adapter);

indicator.setViewPager(pager);
//如果我们要对ViewPager设置监听,用indicator设置就行了
indicator.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {

}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {

}
@Override
public void onPageScrollStateChanged(int arg0) {

}
});

//初始化显示第一页
pages.get(0).initData();
indicator.setViewPager(pager);
indicator.setCurrentItem(curIndex);

这个效果我如果单独创建项目运行,发现可以运行,一旦加到我的项目当中后就出现上面我说的错误
具体错去代码如下:
09-26 21:13:05.732: E/AndroidRuntime(22428): java.lang.IllegalStateException: ViewPager has not been bound.
09-26 21:13:05.732: E/AndroidRuntime(22428): at com.example.abvc_helper.ui.pageindicator.TabPageIndicator.setCurrentItem(TabPageIndicator.java:242)
09-26 21:13:05.732: E/AndroidRuntime(22428): at com.example.abvc_helper.ui.pageindicator.TabPageIndicator.onMeasure(TabPageIndicator.java:118)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1201)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.onMeasure(LinearLayout.java:555)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1374)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.measureVertical(LinearLayout.java:663)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.measureVertical(LinearLayout.java:815)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1374)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.measureVertical(LinearLayout.java:663)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4788)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
09-26 21:13:05.732: E/AndroidRuntime(22428): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2114)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.View.measure(View.java:12773)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1147)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2642)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.os.Handler.dispatchMessage(Handler.java:99)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.os.Looper.loop(Looper.java:154)
09-26 21:13:05.732: E/AndroidRuntime(22428): at android.app.ActivityThread.main(ActivityThread.java:4624)
09-26 21:13:05.732: E/AndroidRuntime(22428): at java.lang.reflect.Method.invokeNative(Native Method)
09-26 21:13:05.732: E/AndroidRuntime(22428): at java.lang.reflect.Method.invoke(Method.java:511)
09-26 21:13:05.732: E/AndroidRuntime(22428): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
09-26 21:13:05.732: E/AndroidRuntime(22428): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
09-26 21:13:05.732: E/AndroidRuntime(22428): at dalvik.system.NativeStart.main(Native Method)

希望给位大神能帮我解决下,谢谢了。

3个回答

qq_16430735
qq_16430735   2015.06.24 17:34

跟你ViewPager里的Fragment有关,你可以试试吧TabPagedicator和UnderlinePageIndicator都设置"gone"

ofreelander
ofreelander 但是indicator 就看不到了。这怎么办
接近 3 年之前 回复
liyanzhenabc123
liyanzhenabc123   2016.01.22 10:06

你在indicator与viewpager关联之前,将indiacator显示出来就行了。

qq_37307794
qq_37307794   2017.01.10 23:26

我用了为什么还是加载不了数据

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!