嘿,我對創建android應用程序相當陌生。我想在操作欄中創建三個選項卡。我已經通過使用New-> Android Activity->使用Swipe和Tabs導航來創建它們。Android中的選項卡,如何創建內容
這就是我在MainActivity的代碼(使用android.com的教程之一):
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) {
// Create a new TextView and set its text to the fragment's section
// number argument value.
int current_section = getArguments().getInt(ARG_SECTION_NUMBER);
switch(current_section){
case 1:
{
EditText element1 = new EditText(getActivity());
element1.setHint(R.string.edit_text_hint);
element1.setGravity(Gravity.TOP);
element1.setPadding(40,40,40,0);
element1.setSingleLine();
TextView textView = new TextView(getActivity());
textView.setGravity(Gravity.CENTER);
textView.setText("Search");
return element1;
}
case 2:
{
TextView textView = new TextView(getActivity());
textView.setGravity(Gravity.CENTER);
textView.setText("User Account");
return textView;
}
case 3:
{
TextView textView = new TextView(getActivity());
textView.setGravity(Gravity.CENTER);
textView.setText("Last Updated");
return textView;
}
}
TextView textView1 = new TextView(getActivity());
textView1.setGravity(Gravity.CENTER);
// textView.setText(Integer.toString(getArguments().getInt(
// ARG_SECTION_NUMBER)));
return textView1;
}
}
在三個選項卡的
所以就有了不同的項目顯示,很遺憾,只能顯示一個 - 而不是更多。我認爲這是一個相當簡單的問題,但我只是沒有弄清楚這是如何工作的。 希望你能幫助我。
好吧,我想類似的東西。那麼究竟該怎麼做呢?我應該爲每個選項卡使用單獨的xml文件還是爲MainActivity.class中的每個選項卡定義佈局?感謝您的快速幫助:) – chrissik
我更新了答案。花一些時間閱讀文檔。它在那裏。 – Oritm
並且不要忘記在答案左側標記(V)/ Upvote(^)正確的答案;) – Oritm