我正在尝试使用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
有人帮帮我.....
答案 0 :(得分: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