0

我正在使用一个视图寻呼机,它有 3 个包含不同表单的布局。我有一个按钮来保存来自不同布局的更改数据如何在按钮单击时从不同布局获取数据?请帮忙

             @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            // Inflate the layout containing a title and body text.



        if(mPageNumber==0)
        {

         //LoginActivity loginActivity=new LoginActivity();
         //System.out.println("Hello"+loginActivity.loginData);
         rootView = (ViewGroup) inflater.inflate(R.layout.layout2, container, false);
        ((TextView) rootView.findViewById(R.id.fullnameedit)).setText(name);
        ((TextView) rootView.findViewById(R.id.usernameedit)).setText(username);
        ((EditText) rootView.findViewById(R.id.emailedit)).setText(email);
        ((EditText) rootView.findViewById(R.id.passedit)).setText(address);
        ((TextView) rootView.findViewById(R.id.emailtext)).addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
                System.out.println("assssasaas");
                if (((EditText) rootView.findViewById(R.id.passedit)).getText().toString().compareTo(s.toString()) != 0)
                {
                    // your code ...

                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub
                System.out.println("fsdfhahfadhsf;osd");

            }

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                System.out.println("ighadfigadwfuiqwl");
                if (((EditText) rootView.findViewById(R.id.passedit)).getText().toString().compareTo(s.toString()) != 0)
                {
                    // your code ...
                    email=((EditText) rootView.findViewById(R.id.passedit)).getText().toString().toString();
                    System.out.println(email+"editable");
                }
            }
        });


        System.out.println(mPageNumber+" page 0");


        }
        else if(mPageNumber==1)
        {
             rootView = (ViewGroup) inflater.inflate(R.layout.layout3, container, false);
             ((EditText) rootView.findViewById(R.id.mobileph)).setText(mobileno);
             ((EditText) rootView.findViewById(R.id.home)).setText(homephone);
             ((EditText) rootView.findViewById(R.id.cit)).setText(city);
             ((EditText) rootView.findViewById(R.id.countrry)).setText(country);
             ((EditText) rootView.findViewById(R.id.postall)).setText(zipcode);
             ((EditText) rootView.findViewById(R.id.countyy)).setText(country);
             System.out.println(mobileno+" "+homephone+" "+city+" "+country+" "+county+" "+zipcode);
             System.out.println(mPageNumber+" page 1"); 
        }
        else if(mPageNumber==2)
        {
             rootView = (ViewGroup) inflater.inflate(R.layout.layout4, container, false);
             ((EditText) rootView.findViewById(R.id.birth)).setText(dob);
             ((EditText) rootView.findViewById(R.id.about)).setText(aboutme);
             System.out.println(mPageNumber+" page 2");
        }
        else if(mPageNumber==3)
        {
             rootView = (ViewGroup) inflater
                        .inflate(R.layout.layout5, container, false);
             ((EditText) rootView.findViewById(R.id.facebuk)).setText(facebook);
             ((EditText) rootView.findViewById(R.id.twitterr)).setText(twitter);
             ((EditText) rootView.findViewById(R.id.myspacee)).setText(icq);
             ((EditText) rootView.findViewById(R.id.linkedinjn)).setText(linked);
             System.out.println(mPageNumber+" page 3");
        }
        // Set the title view to show the page number.
        //((TextView) rootView.findViewById(android.R.id.button1)).setText(
              //  getString(R.string.title_template_step, mPageNumber + 1));

        return rootView;
    }
4

1 回答 1

0

onCreateView() 仅在创建片段时调用一次。您应该将 onPageChangeListener 添加到您的 viewPager 中,并在此侦听器中创建充气对象,然后对所需的布局进行充气。

于 2013-02-02T08:29:03.310 回答