2012-11-23 33 views
0

浏览量我有一个列表视图包含的项目苹果,香蕉,橘子......在第二屏幕活动 当我在特定项目点击苹果它定位到的详细信息屏幕列表视图项的onclick进入下一个活动

这里输出有出现像苹果..如果我刷卡页面,然后香蕉和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; 
      } 

     } 

    } 


    } 

回答

0

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

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

而且你temperList不应该在你的适配器(没有理由,你把它当作一个PARAM)静态只是使它final - private final ArrayList<String> temperList;

如果还是不行修复它,请发布更多结构化的分隔代码,以便我们可以看到你的应用程序是如何构建的。该适配器看起来很好,所以它可能是你的写/重写阵列的情况。

相关问题