0

我正在尝试使用 pagertitlestrip 创建一个简单的视图寻呼机,这是我的代码:Adapter_PagerAdapter.java

  package com.kolmajor.adabiyat;

 import java.util.List;

 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentPagerAdapter;

  public class Adapter_PagerAdapter extends FragmentPagerAdapter {


private List<Fragment> fragments;
/**
 * @param fm
 * @param fragments
 */
public Adapter_PagerAdapter(FragmentManager fm, List<Fragment> fragments) {
    super(fm);
     this.fragments = fragments;

}
/* (non-Javadoc)
 * @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
 */
@Override
public Fragment getItem(int position) {
    return this.fragments.get(position);
}

/* (non-Javadoc)
 * @see android.support.v4.view.PagerAdapter#getCount()
 */
@Override
public int getCount() {
    return this.fragments.size();
}
 }

FragmentActivity_Main.java

package com.kolmajor.adabiyat;

 import java.util.ArrayList;
  import java.util.List;
   import java.util.Vector;

   import android.app.Activity;
      import android.app.Fragment;
     import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.PagerAdapter;
    import android.support.v4.view.ViewPager;

    public class FragmentActivity_Main extends FragmentActivity {


private Adapter_PagerAdapter mPagerAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.activity_main);
    //initialsie the pager
    this.initialisePaging();
}

/**
 * Initialise the fragments to be paged
 */
private void initialisePaging() {

    List<Fragment> fragments = new Vector<Fragment>();
    fragments.add(Fragment.instantiate(this, Fragment_Writers.class.getName()));
    fragments.add(Fragment.instantiate(this, Fragment_Books.class.getName()));
    this.mPagerAdapter  = new Adapter_PagerAdapter(super.getSupportFragmentManager(), fragments);

    ViewPager pager = (ViewPager)super.findViewById(R.id.viewpager);
    pager.setAdapter(this.mPagerAdapter);
}

}

我不知道为什么 eclipse 在这一行显示错误:

this.mPagerAdapter  = new Adapter_PagerAdapter(super.getSupportFragmentManager(), fragments);

错误 :

The constructor Adapter_PagerAdapter(FragmentManager, List<Fragment>) is undefined

请有人帮助我......

4

1 回答 1

2

这是因为在你的Adapter_PagerAdapter.java你正在使用

import android.support.v4.app.Fragment;

但在FragmentActivity_Main.java你使用

import android.app.Fragment;

所以你的错误信息真正说的是:

The constructor Adapter_PagerAdapter(FragmentManager, List<Fragment>) is undefined

因为

Adapter_PagerAdapter(FragmentManager, List<android.support.v4.app.Fragment>) is defined instead
于 2013-11-07T23:34:58.150 回答