嘿,我对创建 android 应用程序很陌生。我想在操作栏中创建三个选项卡。我已经通过使用 New->Android Activity-> Navigation with Swipe and Tabs 创建它们来完成此操作。
这就是我的 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;
}
}
所以在三个选项卡中的每一个都有一个不同的项目显示,不幸的是只能显示一个 - 而不是更多。我认为这是一个很简单的问题,但我只是不知道这是如何工作的。希望你能帮我解决这个问题。