【发布时间】:2012-08-26 02:39:51
【问题描述】:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0: return getString(R.string.title_section1).toUpperCase();
case 1: return getString(R.string.title_section2).toUpperCase();
case 2: return getString(R.string.title_section3).toUpperCase();
}
return null;
}
}
/**
* A dummy fragment representing a section of the app, but that simply displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
public DummySectionFragment() {
}
public static final String ARG_SECTION_NUMBER = "section_number";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
textView.setGravity(Gravity.CENTER);
Bundle args = getArguments();
textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
return inflater.inflate(R.layout.fragment_content1, container, false);
}
}
}
上面的代码是来自 ViewPager SDK 的模板,当我从一页滑动到一页时,它只放置文本 1 到 3。问题是当我滑动它时如何替换该文本并放置我自己的布局 xml,并且是否可以使用具有此功能的 WebView。例如:当活动加载时,它会转到 google.com,然后当我滑动到其他页面时,每次滑动时它都会更改 WebView 的 url?希望有人可以帮助我...
【问题讨论】:
-
你应该试着更好地解释你想要什么。代码是否正常工作或发生了什么不好的事情?
-
对不起,我的英语不好,我刚刚更新了我的问题,希望现在更清楚......
标签: android android-layout android-fragments android-viewpager fragmentpageradapter