viewpager添加视图中显示错误

时间:2013-11-18 05:14:29

标签: android google-app-engine android-viewpager

这是xml布局视图寻呼机的视图寻呼机代码

<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="fill_parent"
    android:layout_height="fill_parent" />

此代码显示视图分页器行中包含“((ViewPager)container.addView(viewlayout);”的错误,其中包含在实例化内部函数中添加视图的视图寻呼机。如何解决此错误请帮助输出。

public class Fullscreenimage extends PagerAdapter {
public Integer[] images1 = { R.drawable.s_1, R.drawable.s_2, R.drawable.s_3 };

public Context mContext;

public Fullscreenimage(Context context) {
    super();
    this.mContext = context;

    // TODO Auto-generated constructor stub
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public boolean isViewFromObject(View arg0, Object arg1) {
    // TODO Auto-generated method stub
    return false;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    // TODO Auto-generated method stub
    super.destroyItem(container, position, object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    // TODO Auto-generated method stub
    LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
    View viewlayout = inflater.inflate(R.layout.layout_fullscreen_view,container,false);
    ImageView imageview=(ImageView) viewlayout.findViewById(R.id.imgDisplay);
    imageview.setImageResource(images1[position]);
     ((ViewPager) container.addView(viewlayout);
    return viewlayout;
}

}

1 个答案:

答案 0 :(得分:1)

试试这个。

In Your code 

((ViewPager) container.addView(viewlayout,0);

在您的代码的上一行中,您错过了“)”。这就是它给出错误的原因。 试试这个然后就可以修复了。

((ViewPager) container).addView(viewlayout,0);