你應該通過編輯添加新的選項卡預先生成
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}
DummyScetionFragment其實你想通過選擇特定的標籤,查看片段,所以你應該定義自己的片段(與他們各自的佈局文件在XML)根據這個預生成的例子:
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_dummy,
container, false);
TextView dummyTextView = (TextView) rootView
.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
return rootView;
}
}
你試過研究這個嗎?在發佈問題之前,你應該這樣做。 –
爲了記錄,您「更改標籤名稱」只是更改標籤名稱所引用的** String's **名稱。所以String名稱爲title_section1,你正在改變該String名稱。那麼選項卡名稱被設置爲無論title_section1是什麼,所以這就是如何工作。添加更多的字符串只是添加更多的字符串。就這麼簡單。它不會爲您創建佈局。 –
@mikeyaworski我試過了,但是在任何地方找不到答案......:/ – user3023946