新的和正在使用 ViewPager,遇到一些困难希望您提供一些建议...
ViewPagerAdapter class
public class ViewPagerAdapter extends FragmentPagerAdapter
{
private Context _context;
public ViewPagerAdapter(Context context, FragmentManager fm)
{
super(fm);
_context=context;
}
@Override
public Fragment getItem(int position)
{
Fragment f = new Fragment();
switch(position){
case 0:
f=App_Intro.newInstance(_context);
break;
case 1:
f=LayoutTwo.newInstance(_context);
break;
}
return f;
}
@Override
public int getCount()
{
return 2;
}
}
ViewPagerStyle1Activity 类
public class ViewPagerStyle1Activity extends FragmentActivity
{
private ViewPager _mViewPager;
private ViewPagerAdapter _adapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpView();
setTab();
}
private void setUpView()
{
_mViewPager = (ViewPager) findViewById(R.id.viewPager);
_adapter = new ViewPagerAdapter(getApplicationContext(),getSupportFragmentManager());
_mViewPager.setAdapter(_adapter);
_mViewPager.setCurrentItem(0);
}
private void setTab()
{
_mViewPager.setOnPageChangeListener(new OnPageChangeListener()
{
@Override
public void onPageScrollStateChanged(int position) {}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {}
@Override
public void onPageSelected(int position)
{
// TODO Auto-generated method stub
switch(position)
{
case 0:
findViewById(R.id.first_tab).setVisibility(View.VISIBLE);
findViewById(R.id.second_tab).setVisibility(View.INVISIBLE);
break;
case 1:
findViewById(R.id.first_tab).setVisibility(View.INVISIBLE);
findViewById(R.id.second_tab).setVisibility(View.VISIBLE);
break;
}
}
});
}
}
App_Intro 类
public class App_Intro extends Fragment
{
public static Fragment newInstance(Context context)
{
App_Intro f = new App_Intro();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
{
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.app_introduce_scroll, null);
Button calpaidBtn = (Button) findViewById(R.id.calpaidBtn); //RED UNDERLINE ERROR
calpaidBtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent (Intent.ACTION_VIEW,
Uri.parse("https://abc.com"));
startActivity(intent);
return;
}
});
return root;
}
}
问题:
它在App_Intro
类中用红色下划线findViewById
表示“ The method findViewById(int) is undefined for the type App_Intro
”
如何解决?实际上如何将不同的活动放入 ViewPager?有没有例子?
提前谢谢了!