在按钮点击父类时,无法从视图寻呼机的不同布局接收数据

时间:2013-02-02 08:12:57

标签: android android-viewpager

我正在使用一个视图寻呼机,它有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;
    }

1 个答案:

答案 0 :(得分:0)

onCreateView()仅在创建片段时调用一次。你应该将onPageChangeListener添加到你的viewPager中,在这个监听器中你应该创建inflater对象,然后给你想要的布局充气。