2013-02-27 2 views
3

두 탭 중 FragmentActivity을 만들었습니다. 내가 보여줄 필요가 2 탭 지금Android 다음 탭에 데이터를 표시하고 저장하십시오.

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

이 2 tabs에 내가 fragments 다른 2를 만든 다음 FragmentActivityCode 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; 
       } 
      } 

FragmentPagerAdapter를 사용하여 안드로이드 개발자 튜토리얼에서 아주 기본적인 Tab 예입니다 첫 번째 탭의 NameEmail의 입력 값은 두 번째 탭의 확인시 database에 저장해야합니다. 하지만 여기에 내가 붙어있다. first tab의 데이터를 어떻게 보관할 수 있는지 알 수 없습니까? 도와주세요.

+0

당신은 http://saigeethamn.blogspot.in/2009/10/shared-preferences-android-developer.html 이 링크 – Syn3sthete

+0

이에서보세요 체크 매우 쉽게 값을 저장하는 SharedPreference를 사용할 수 있습니다 http://developer.android.com/training/basics/fragments/communicating.html – nedaRM

답변

0

한 접근법은 싱글 톤 DP를 사용할 수 있습니다. 필드에는 이름, 전자 메일 등이있는 개체가 하나만 있습니다. 첫 번째 조각에있을 때 setter를 사용하여 이름 및 전자 메일 필드를 설정하고 두 번째 조각에서 getters를 사용하여 액세스하십시오.

확인시 전체 개체를 데이터베이스에 삽입 할 수 있습니다.

관련 문제