listview项目在下一个活动中点击进入网页浏览

时间:2012-11-23 14:25:18

标签: android

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

这里输出必须像苹果..如果我刷页面然后香蕉和nextswipe orage

苹果 - >香蕉 - >橙

但我得到的输出像苹果 - >苹果 - >苹果。

  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;
            }

        }

    }


    }

1 个答案:

答案 0 :(得分:0)

args.putString("name",temperList.get(position) );不应该在ThingFragment内作为静态。

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

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

如果这不能解决问题,请发布更加结构化的单独代码,以便我们了解您的应用程序是如何构建的。适配器看起来很好,所以可能会在某些时候写入/覆盖数组。