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);
}
}
}
上面的代碼是SDK for ViewPager中的模板,當我從一頁滑動到一頁時,它僅將文本1到3。問題是我如何替換該文本並在刷卡時放置自己的佈局xml,並且可以使用此功能的WebView。例如:當活動加載它去google.com然後當我滑動到其他頁面它每次我刷卡時更改WebView的URL?希望有人能幫助我......如何使用ViewPager切換到其他佈局?
你應該嘗試更好地解釋你想要的。代碼是否工作或者發生了什麼壞事? – Luksprog
抱歉我的英文不好,我只是更新了我的問題,希望現在更清楚了...... – homi3kh