Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将绑定的数据传递到以viewPager启动的片段_Android_Android Viewpager_Fragmentpageradapter - Fatal编程技术网

Android 将绑定的数据传递到以viewPager启动的片段

Android 将绑定的数据传递到以viewPager启动的片段,android,android-viewpager,fragmentpageradapter,Android,Android Viewpager,Fragmentpageradapter,在EclipseV22.6.2中,一个名为Act1的活动是有目的地启动的。 一些数据通过使用putExtras作为捆绑包传递 Intent intent = new Intent(MyMain.this, Act1.class); Bundle bundle = new Bundle(); bundle.putString("id", _productid); bundle.putString("name", _productname); bundle.putStr

在EclipseV22.6.2中,一个名为Act1的活动是有目的地启动的。
一些数据通过使用putExtras作为捆绑包传递

Intent intent = new Intent(MyMain.this, Act1.class);
Bundle bundle = new Bundle();               
bundle.putString("id", _productid);
bundle.putString("name", _productname);
bundle.putString("price", _productprice);
bundle.putString("t1", _t1);
intent.putExtras(bundle);
startActivity(intent);
在Act1中,一些文本视图填充了来自bundle中传递的参数的数据

txtpid = (TextView) getView().findViewById(R.id.txtdisplaypid);
txtpname = (TextView) getView().findViewById(R.id.txtdisplaypname);
txtpprice = (TextView) getView().findViewById(R.id.txtdisplaypprice);
txtt1 = (TextView) getView().findViewById(R.id.txtdisplayt1);
txtpid.setText(getArguments().getString("id"));
txtpname.setText(getArguments().getString("name"));
txtpprice.setText(getArguments().getString("price"));
txtt1.setText(getArguments().getString("t1"));
在Act1中,使用FragmentPagerAdapter的ViewPager用于启动名为Fragm1的片段。没有使用意图

我的两个问题:
如何将捆绑的数据传递给Frag1?
Frag1拥有数据后,如何访问


样本代码将不胜感激

事实证明这很容易。 形成一个bundle以在调用应用程序Act1中发送

           public Bundle getDetailBundle(){

              // define variables and populate
              t1 = (i.getExtras().getString("t1"));
              t2 = (i.getExtras().getString("t2"));
              t3 = (i.getExtras().getString("t3"));
              t4 = (i.getExtras().getString("t4"));

              Bundle bundle = new Bundle();

              bundle.putString("t1", t1);
              bundle.putString("t2", t2);                                         
              bundle.putString("t3", t3);
              bundle.putString("t4", t4);             

              return bundle;
       }
使用框架中的捆绑

        public String stringo;
        public Bundle bunny;

        // be sure to place the following two lines of code in or after OnCreateView or //else they will end up null.

        bunny = ((Act1) getActivity()).getDetailBundle();
        textView.setText(bunny.getString("t1"));