2012-11-23 63 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;

如果還是不行修復它,請發佈更多結構化的分隔代碼,以便我們可以看到你的應用程序是如何構建的。該適配器看起來很好,所以它可能是你的寫/重寫陣列的情況。

相關問題