我创建了FragmentActivity
2 个选项卡。这是一个非常基本的Tab
例子,来自 Android 开发者教程 using FragmentActivity
and FragmentPagerAdapter
Code Here
public class FragmentPagerSupport extends FragmentActivity implements
ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
static final int NUM_ITEMS = 10;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_pager);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
...........
}
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
Bundle args = new Bundle();
switch (position) {
case 0:
fragment = new Fragment01();
args.putInt(Fragment01.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
break;
case 1:
fragment = new Fragment02();
args.putInt(Fragment02.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
break;
return fragment;
}
}
然后我fragments
为 2创建了 2 个不同的tabs
:
public static class Fragment01 extends Fragment {
private EditText mName;
private EditText mEmail1;
public static final String ARG_SECTION_NUMBER = "2";
public Fragment01() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_customer_add, container, false);
mName = (EditText) v.findViewById(R.id.customer_add_name);
mEmail = (EditText) v.findViewById(R.id.customer_add_email);
View confirmButton = v.findViewById(R.id.customer_add_button);
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
......................
}
});
}
}
现在在第二个选项卡中,我需要显示第一个选项卡的输入值Name
和Email
来自第二个选项卡的确认需要保存在database
. 但在这里我卡住了。我不知道如何保留数据first tab
?请帮忙。