3

FragmentActivity2 つのタブを作成しました。これは、Code HereTabを使用した Android 開発者チュートリアルの非常に基本的な例です。FragmentActivityFragmentPagerAdapter

    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 に対して 2tabsつの異なるものを作成しました。

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) {
            ......................
                             }
            });
     }
  }

Name2 番目のタブでは、1 番目のタブの入力値と1 番目のタブからの入力値を表示する必要があり、Email2 番目のタブから確認するには、database. しかし、ここで私は立ち往生しました。からデータを保持する方法がわかりませんfirst tab。助けてください。

4

1 に答える 1

0

1つのアプローチは、シングルトンDPを使用することです。Name、Emailなどをフィールドとして持つオブジェクトは1つだけです。最初のフラグメントにいるときにセッターを使用して[名前]フィールドと[電子メール]フィールドを設定し、2番目のフラグメントにあるゲッターを使用してそれらにアクセスします。

確認すると、オブジェクト全体をデータベースに挿入できます。

于 2013-02-27T05:37:03.813 に答える