0

我有一个包含项目苹果,香蕉,橙色的列表视图...在第二个屏幕活动中,当我点击苹果上的特定项目时,它导航到详细信息屏幕

这里的输出必须看起来像苹果..如果我滑动页面然后是香蕉,然后是 nextswipe orage

苹果-->香蕉-->橙子

但是我得到了像apple-->apple-->apple这样的输出。

  Intent detailIntent =new Intent(SecondScreen.this, Details.class);            

    startActivity(detailIntent);


    public class MyApplication extends Application {

        ArrayList<String> totalvalue  = new ArrayList<String>();

    }


    public class Details extends FragmentActivity{

        MyApplication app;
        ViewPager pager;
      MyFragmentPagerAdapter pagerAdapter;     
     public static int position ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.detail);    
        app = ((MyApplication) getApplicationContext());
        pager = (ViewPager) findViewById(R.id.pager);

        FragmentManager fm = getSupportFragmentManager();      
        pagerAdapter = new MyFragmentPagerAdapter(fm,app.totalvalue);   
          pager.setAdapter(pagerAdapter);

      }



    public static class MyFragmentPagerAdapter extends FragmentPagerAdapter {


        private static  ArrayList<String> temperList;



        public MyFragmentPagerAdapter(FragmentManager fm, ArrayList<String> totalvalue ) {
             super(fm);
             this.temperList = totalvalue;
        }


        public Fragment getItem(int position) {

            return ThingFragment.newInstance((temperList.get(position)));
        }

        @Override
        public int getCount(){

        return temperList.size();

        }

         private static class ThingFragment extends Fragment {       
                private String name1;
             static ThingFragment newInstance(String string ) {

                    ThingFragment f = new ThingFragment();
                    Bundle args = new Bundle();

            args.putString("name",temperList.get(position) );
                    f.setArguments(args);

                    return f;
                }



                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    name1 = getArguments().getString("name");
                }

                @Override
                public View onCreateView(LayoutInflater inflater, ViewGroup container,                       Bundle savedInstanceState) {

                    View v = inflater.inflate(R.layout.myfragment_layout, container, false);
                    TextView t = (TextView)v.findViewById(R.id.prodcutt);
                    t.setText(""+ name1);
                    return v;
            }

        }

    }


    }
4

1 回答 1

0

args.putString("name",temperList.get(position) );在你的内部不应该是可能的ThingFragment,因为它是静态的。

那应该是args.putString("name",string);

此外temperList,您的适配器不应该是静态的(没有理由,您将它作为参数传递)只是让它final-private final ArrayList<String> temperList;

如果这不能解决问题,请发布更多结构化的分隔代码,以便我们可以了解您的应用程序是如何构建的。适配器看起来不错,因此您可能会在某个时候写入/覆盖数组。

于 2012-11-23T14:42:20.967 回答