如何将活动添加到片段适配器列表

时间:2016-12-25 19:12:21

标签: android android-fragments android-activity fragment

 private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFrag(new CompanyActivity(), "ONE");
        adapter.addFrag(new CompanyActivitytwo(), "TWO");
        adapter.addFrag(new CompanyActivitythree(), "THREE");
        viewPager.setAdapter(adapter);
    }

class' CompanyActivity(),

CompanyActivitytwo(),

CompanyActivitythree()

不是片段,但我想将它们添加到片段列表中 他们都延伸AppCompatActivity 这是CompanyActivity类代码

public class CompanyActivity extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.huf);

    } 

    public void one(View view) {
        Intent first=new Intent(CompanyActivity.this,CompanyDetalies.class);

        startActivity(first);
    }

    public void two(View view) {  Intent first=new Intent(CompanyActivity.this,CompanytwoDetalies.class);
        startActivity(first);
    }

    public void three(View view) { Intent first=new Intent(CompanyActivity.this,CompanythreeDetalies.class);
        startActivity(first);
    }

    public void four(View view) { Intent first=new Intent(CompanyActivity.this,CompanyfourDetalies.class);
        startActivity(first);
    }

    public void five(View view) { Intent first=new Intent(CompanyActivity.this,CompanyfiveDetalies.class);
        startActivity(first);
    }

    public void six(View view) {
        Intent first=new Intent(CompanyActivity.this,CompanysixDetails.class);
        startActivity(first);
    }


}

1 个答案:

答案 0 :(得分:0)

您不能将ViewPager用于活动,您需要将它们转换为碎片。有关详情,请参阅此处:Android PagerView between Activities