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

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

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

        将数据从 Activity 发送到 TabLayout 片段

        时间:2023-10-03

            <tbody id='bX81z'></tbody>

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

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

          <tfoot id='bX81z'></tfoot>
              • <bdo id='bX81z'></bdo><ul id='bX81z'></ul>
                • 本文介绍了将数据从 Activity 发送到 TabLayout 片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在设计一个我遇到问题的应用程序,

                  I am designing a application in which i am facing problem,

                  我在 MainActivity.class 中有一个 String date; 并且有两个片段.

                  I have a String date; in MainActivity.class and there are two fragments.

                  入站日期 &出境日期

                  我是由 TabLayout & 设计的ViewPager,当我将日期发送到 Fragments & 时出现问题必须在两个片段上通过 POST 请求调用 WebServices.

                  I designed it by TabLayout & ViewPager, I am getting issue when i sending date to fragments & have to call WebServices by POST request on both the fragments.

                  下面是我在 MainActivity.class 中的日期,我如何将此日期发送到片段和调用 jsonRequest 并将 Recyclerview 设置为两个片段,或者如果我将 jsonRequest 调用到 MainActivity 本身,那么我如何向两个片段显示.

                  Below is the date i have in MainActivity.class, How i send this date to both the fragments & call jsonRequest and set Recyclerview to both the fragments Or if i call the jsonRequest to MainActivity itself then how can i display to both the fragments.

                   date = getIntent().getStringExtra("DATE");
                      Log.e("DATE",""+date);
                  

                  ViewPager &标签布局代码:

                  ViewPager & TabLayout Code:

                   private void setupViewPager(ViewPager viewPager) {
                      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
                      adapter.addFrag(new InBoundDate(),"INBOUND");
                      adapter.addFrag(new OutBoundDate(),"OUTBOUND");
                      viewPager.setAdapter(adapter);
                  
                  }
                  
                  //viewPager adapter ----- inbound & outbound
                  public class ViewPagerAdapter extends FragmentPagerAdapter {
                      private final List<Fragment> mFragmentList = new ArrayList<>();
                      private final List<String> mFragmentTitleList = new ArrayList<>();
                  
                      public ViewPagerAdapter(FragmentManager manager) {
                          super(manager);
                      }
                  
                      @Override
                      public android.support.v4.app.Fragment getItem(int position) {
                          return mFragmentList.get(position);
                      }
                  
                      @Override
                      public int getCount() {
                          return mFragmentList.size();
                      }
                  
                      public void addFrag(android.support.v4.app.Fragment fragment, String title) {
                          mFragmentList.add(fragment);
                          mFragmentTitleList.add(title);
                      }
                  
                      @Override
                      public CharSequence getPageTitle(int position) {
                          return mFragmentTitleList.get(position);
                      }
                  }
                  

                  推荐答案

                  我通过互联网搜索得到了这个问题的答案.在这个问题中,我必须将字符串发送到 MainActivity.java 到同一 Activity 上存在的片段.

                  I got the answer of this question by searching over the internet. In this question i have to send string to MainActivity.java to fragments present on same Activity.

                  注意:我们必须创建捆绑对象 &必须通过捆绑发送字符串(任何数据类型).

                  Note : We have to create bundle object & have to send string(any dataType) by bundle.

                  我有两个片段 InBoundDate &OutBoundDate.

                  I have two fragments InBoundDate & OutBoundDate.

                  MainActivity.java中的setupViewpager()

                  In MainActivity.java in setupViewpager ()

                   private void setupViewPager(ViewPager viewPager) {
                      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
                  
                      //bundle
                      bundle =new Bundle();
                      bundle.putString("DATE","2017-10-19");
                  
                      InBoundDate frag_in = new InBoundDate();
                      OutBoundDate frag_out = new OutBoundDate();
                  
                      frag_in.setArguments(bundle);
                      frag_out.setArguments(bundle);
                      adapter.addFrag(frag_in,"INBOUND");
                      adapter.addFrag(frag_out,"OUTBOUND");
                      viewPager.setAdapter(adapter);
                  
                  }
                  

                  ViewPager 适配器:

                    //viewPager adapter ----- inbound & outbound
                  public class ViewPagerAdapter extends FragmentPagerAdapter {
                      private final List<Fragment> mFragmentList = new ArrayList<>();
                      private final List<String> mFragmentTitleList = new ArrayList<>();
                  
                      public ViewPagerAdapter(FragmentManager manager) {
                          super(manager);
                      }
                  
                      @Override
                      public android.support.v4.app.Fragment getItem(int position) {
                          return mFragmentList.get(position);
                      }
                  
                      @Override
                      public int getCount() {
                          return mFragmentList.size();
                      }
                  
                      public void addFrag(android.support.v4.app.Fragment fragment, String title) {
                          mFragmentList.add(fragment);
                          mFragmentTitleList.add(title);
                      }
                  
                      @Override
                      public CharSequence getPageTitle(int position) {
                          return mFragmentTitleList.get(position);
                      }
                  }
                  

                  在你的 Fragments 中通过这种方式获取字符串:

                  In your Fragments get String by this way :

                      String dateTxt;
                      private Bundle bundle;
                  
                      //within OncreateView
                       bundle = this.getArguments();
                          dateTxt = bundle.getString("DATE");
                          Log.e("DATE_FRAG_INBOUND",""+dateTxt);
                  

                  这篇关于将数据从 Activity 发送到 TabLayout 片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在全屏中滑动选定的网格图像 下一篇:嵌套片段可能吗?

                  相关文章

                  1. <small id='itNjX'></small><noframes id='itNjX'>

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