<i id='EwkGE'><tr id='EwkGE'><dt id='EwkGE'><q id='EwkGE'><span id='EwkGE'><b id='EwkGE'><form id='EwkGE'><ins id='EwkGE'></ins><ul id='EwkGE'></ul><sub id='EwkGE'></sub></form><legend id='EwkGE'></legend><bdo id='EwkGE'><pre id='EwkGE'><center id='EwkGE'></center></pre></bdo></b><th id='EwkGE'></th></span></q></dt></tr></i><div id='EwkGE'><tfoot id='EwkGE'></tfoot><dl id='EwkGE'><fieldset id='EwkGE'></fieldset></dl></div>
  • <legend id='EwkGE'><style id='EwkGE'><dir id='EwkGE'><q id='EwkGE'></q></dir></style></legend>

      <bdo id='EwkGE'></bdo><ul id='EwkGE'></ul>
  • <tfoot id='EwkGE'></tfoot>

        <small id='EwkGE'></small><noframes id='EwkGE'>

      1. 获取不同片段上的 EditText 值

        时间:2023-10-03
          <tbody id='vjKFd'></tbody>

        <small id='vjKFd'></small><noframes id='vjKFd'>

        <tfoot id='vjKFd'></tfoot>
      2. <i id='vjKFd'><tr id='vjKFd'><dt id='vjKFd'><q id='vjKFd'><span id='vjKFd'><b id='vjKFd'><form id='vjKFd'><ins id='vjKFd'></ins><ul id='vjKFd'></ul><sub id='vjKFd'></sub></form><legend id='vjKFd'></legend><bdo id='vjKFd'><pre id='vjKFd'><center id='vjKFd'></center></pre></bdo></b><th id='vjKFd'></th></span></q></dt></tr></i><div id='vjKFd'><tfoot id='vjKFd'></tfoot><dl id='vjKFd'><fieldset id='vjKFd'></fieldset></dl></div>

        • <legend id='vjKFd'><style id='vjKFd'><dir id='vjKFd'><q id='vjKFd'></q></dir></style></legend>
                <bdo id='vjKFd'></bdo><ul id='vjKFd'></ul>

                  本文介绍了获取不同片段上的 EditText 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从不同片段的 editTexts 获取一些文本.所以我首先要做的是定义我的 mPagermPagerAdapter:

                  I am trying to get some text from editTexts on different fragments. So what I do first is define my mPager and mPagerAdapter:

                  a_Atenuacion 活动

                  public class a_Atenuacion extends FragmentActivity{
                  
                      private static final int NUM_PAGES = 3;
                      /**
                       * The pager widget, which handles animation and allows swiping horizontally to access previous
                       * and next wizard steps.
                       */
                      private ViewPager mPager;
                  
                      /**
                       * The pager adapter, which provides the pages to the view pager widget.
                       */
                      private PagerAdapter mPagerAdapter;
                  
                      /** Called when the activity is first created. */
                      @Override
                      public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                  
                          setContentView(R.layout.a_dat_viewpager);
                  
                          // Instantiate a ViewPager and a PagerAdapter.
                          mPager = (ViewPager) findViewById(R.id.pager);
                          mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
                          mPager.setAdapter(mPagerAdapter);
                  
                  
                      }
                      private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
                          public ScreenSlidePagerAdapter(FragmentManager fm) {
                              super(fm);
                          }
                          @Override
                          public Fragment getItem(int position) {
                              switch(position){
                                  case 0:
                                      return new a_Dat_Inicio1();
                                  case 1:
                                      return new a_Dat_Inicio2();
                                  case 2:
                                      return new a_Dat_Inicio3();
                              }
                              return null;
                          }
                          @Override
                          public int getCount() {
                              return NUM_PAGES;
                          }
                      }
                  }
                  

                  然后我得到了我的 3 个片段类(第一个和第二个布局都有一个 editText,但第三个有一个 editText 和一个 button).按钮功能是当我在最后一个片段(fragment3)中时,它采用信息形式(不同的editTexts)并发送到另一个活动.

                  Then I get my 3 fragments classes (Both 1st and 2nd layouts have an editText, but the 3rd one has an editText and a button). The button function is that when I am in the last fragment (fragment3) it take info form (different editTexts) and send to another activity.

                  a_Dat_Inicio1 片段

                  public class a_Dat_Inicio1 extends Fragment {
                  
                      @Override
                      public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          Log.e("Test", "hello");
                      }
                  
                      @Override
                      public void onActivityCreated(Bundle savedInstanceState) {
                          super.onActivityCreated(savedInstanceState);
                      }
                  
                      @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                               Bundle savedInstanceState) {
                          View view = inflater.inflate(R.layout.a_dat_inicio1, container, false);
                  
                          return view;  
                      }
                  }
                  

                  a_Dat_Inicio3 片段

                  public class a_Dat_Inicio3 extends Fragment {
                  
                      EditText edit3;
                      EditText edit2;
                      EditText edit1;
                  
                      @Override
                      public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          Log.e("Test", "hello");
                      }
                  
                      @Override
                      public void onActivityCreated(Bundle savedInstanceState) {
                          super.onActivityCreated(savedInstanceState);
                  
                      }
                  
                      @Override
                      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                               Bundle savedInstanceState) {
                          final View view = inflater.inflate(R.layout.a_dat_inicio3, container, false);
                  
                  
                          edit1 = (EditText)getActivity().findViewById(R.id.editText1);
                          final String edit11 = edit1.getText().toString();
                          edit2 = (EditText)getActivity().findViewById(R.id.editText2);
                          final String edit22 = edit2.getText().toString();
                          edit3 = (EditText)view.findViewById(R.id.editText3);
                          final String edit33 = edit3.getText().toString();
                  
                          Button but=(Button) view.findViewById(R.id.button);
                  
                          but.setOnClickListener(new View.OnClickListener(){
                              public void onClick(View v) {
                  
                                  //Creamos el bundle
                                  Bundle bundle = new Bundle();
                                  //Le ponemos la variable parametro con el contenido (key, valor)
                                  bundle.putString("edit3", edit33);
                                  bundle.putString("edit2", edit22);
                                  bundle.putString("edit1", edit11);
                                  Intent net= new Intent(v.getContext(),Prueba1.class);
                                  net.putExtras(bundle);
                                  startActivity(net);
                  
                              }
                          });
                  
                          return view;
                      }
                  }
                  

                  最后我在另一个活动(Prueba1.class)上得到了捆绑,奇怪的是我只得到 editText1 的结果(在第一个片段上),其余的都是空的.

                  Finally I get bundle on another activity (Prueba1.class) and it is curious that I only get result for editText1 (on 1st fragment) and rest are null.

                  谁能帮帮我?

                  提前致谢.

                  推荐答案

                  最后我克服了一个接口,这是我认为在已经定义的片段上获得一些东西的唯一方法.

                  finally I get over an interface, that is the only way I think to get soemthing on already defined fragments.

                  我的代码是这样的:

                  第一次定义接口

                  public interface OnEditTextChanged {
                  
                  public void onEditPressed1(String edit1);
                  
                  public void onEditPressed2(String edit1);
                  
                  public void onEditPressed3(String edit1);
                  

                  然后是片段活动:

                  public class a_Dat_Inicio1 extends Fragment {
                  
                  EditText edit;
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      Log.e("Test", "hello");
                  }
                  
                  @Override
                  public void onActivityCreated(Bundle savedInstanceState) {
                      super.onActivityCreated(savedInstanceState);
                  
                  }
                  
                  @Override
                  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                           Bundle savedInstanceState) {
                      View view = inflater.inflate(R.layout.a_1dat_inicio1, container, false);
                      init (view);
                  
                      return view;
                  }
                  
                  OnEditTextChanged editListener;
                  @Override
                  public void onAttach(Activity activity){
                      super.onAttach(activity);
                      try{
                          editListener=(OnEditTextChanged) getActivity();
                      }catch(ClassCastException e){
                          throw new ClassCastException(activity.toString()+"must implemnt onEditPressed");
                      }
                  }
                  
                  private void init(View view) {
                      edit=(EditText) view.findViewById(R.id.editText1);
                  
                      //cada vez que se modifique texto llamar
                      edit.addTextChangedListener(new TextWatcher() {
                  
                          @Override
                          public void afterTextChanged(Editable s) {
                              final String edit11 = edit.getText().toString();
                              editListener.onEditPressed1(edit11);
                  
                          }
                      });
                  

                  最后在我们的主要活动上,调用方法:

                  And finally on our main activity, call the method:

                  public class a_Atenuacion extends FragmentActivity implements OnEditTextChanged {
                  
                  String dat1;
                  String dat2;
                  String dat3;
                  
                  private static final int NUM_PAGES = 3;
                  private PagerAdapter mPagerAdapter;
                  
                  /** Called when the activity is first created. */
                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                  
                      setContentView(R.layout.a_1dat_viewpager);
                  
                      // Instantiate a ViewPager and a PagerAdapter.
                      mPager = (ViewPager) findViewById(R.id.pager);
                      mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
                      mPager.setAdapter(mPagerAdapter);
                  
                  
                      //HERE DO WHATEVER YOU WANT WITH THE DATA CAUGTH ON THE EDIT 1 METHOD
                  
                  
                  }
                  
                  
                  @Override
                  public void onEditPressed1(String edit1) {
                  
                      if(mPager.getCurrentItem()==0){
                          dat1=edit1;
                          Toast bread = Toast.makeText(getApplicationContext(), "edit1", Toast.LENGTH_LONG);
                          bread.show();
                      }
                  }
                  

                  希望这对某人有帮助!!!

                  HOPE this help someone!!!

                  无论如何谢谢!!!

                  这篇关于获取不同片段上的 EditText 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:单个 ListView 内的多个 ViewPagers 崩溃 下一篇:如何在视图寻呼机中自动更改图像,当它到达最后一张图像时,它应该自动到达第一张图像

                  相关文章

                1. <tfoot id='NnA4z'></tfoot><legend id='NnA4z'><style id='NnA4z'><dir id='NnA4z'><q id='NnA4z'></q></dir></style></legend>
                  <i id='NnA4z'><tr id='NnA4z'><dt id='NnA4z'><q id='NnA4z'><span id='NnA4z'><b id='NnA4z'><form id='NnA4z'><ins id='NnA4z'></ins><ul id='NnA4z'></ul><sub id='NnA4z'></sub></form><legend id='NnA4z'></legend><bdo id='NnA4z'><pre id='NnA4z'><center id='NnA4z'></center></pre></bdo></b><th id='NnA4z'></th></span></q></dt></tr></i><div id='NnA4z'><tfoot id='NnA4z'></tfoot><dl id='NnA4z'><fieldset id='NnA4z'></fieldset></dl></div>

                    <small id='NnA4z'></small><noframes id='NnA4z'>

                    • <bdo id='NnA4z'></bdo><ul id='NnA4z'></ul>