构造函数未定义?

时间:2014-11-19 17:42:58

标签: android android-fragments android-actionbar android-viewpager android-fragmentactivity

为什么我收到此错误The constructor MyTabsPagerAdapter(FragmentManager, List<Fragment>) is undefined

下面的代码包含导入以及我如何实例化MyTabsPagerAdapter类。尽管该类存在,但当我实例化它时,我会收到上面提到的错误。

请让我知道我的错误或错过的地方

Code_with_imports

import java.util.ArrayList;
import java.util.List;
import com.example.mqtt_test_00.adapter.MyTabsPagerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

public class MessaginActivity extends FragmentActivity implements ActionBar.TabListener {
private ViewPager  mViewPager;
private MyTabsPagerAdapter mPagerAdapter;
private ActionBar mActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.messagin_activity_layout);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mActionBar = getActionBar();
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    List<Fragment> mFragList = new ArrayList<Fragment>();
    mFragList.add(new Pub_Frag());
    mFragList.add(new Sub_Frag());

    mPagerAdapter = new MyTabsPagerAdapter(getSupportFragmentManager(), mFragList);
    mViewPager.setAdapter(mPagerAdapter);
}

class2MyTabsPagerAdapter

package com.example.mqtt_test_00.adapter;
import java.util.List;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MyTabsPagerAdapter extends FragmentPagerAdapter {

List<Fragment> mFragList;

public MyTabsPagerAdapter(FragmentManager fm, List<Fragment> mFragList) {
    super(fm);
    // TODO Auto-generated constructor stub
    this.mFragList = mFragList;
}

@Override
public Fragment getItem(int arg0) {
    // TODO Auto-generated method stub
    return this.mFragList.get(arg0);

}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return this.mFragList.size();
}

}

1 个答案:

答案 0 :(得分:1)

列表中的碎片类型不同。看看你的进口:

<强> MessaginActivity

import android.app.Fragment;

<强> MyTabsPagerAdapter

import android.support.v4.app.Fragment;

更改MessaginActivity中的片段以支持片段。