2013-07-31 40 views
0

我使用viewpagerindicator,在啓動這個活動時,看起來所有的片段都在加載。 我希望當一個片段啓動剛剛打開,點擊或滑動並進行加載。 未打開的片段將在打開時加載,稍後單擊或輕掃。如何?使viewpagerindicator片段啓動剛剛打開,點擊或滑動並進行加載?

這是我的代碼適配器viewpager

import android.content.Context; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentPagerAdapter; 

public class ViewAdapter extends FragmentPagerAdapter{ 

    private Context _context; 
    String[] page_titles; 

    public ViewAdapter(Context context, FragmentManager fm, String[] page_title){ 
     super(fm); 
     _context = context; 
     this.page_titles = page_title; 
    } 



    @Override 
    public Fragment getItem(int position) { 
     // TODO Auto-generated method stub 

     Fragment f = new Fragment(); 

     switch(position){ 
     case 0: 
      f = ContentActivity.newInstance(_context); 
      break; 

     case 1: 
      f = ContentActivity.newInstance(_context); 
      break; 
     case 2: 
      f = ContentActivity.newInstance(_context); 
      break; 

     } 

     return f; 
    } 

    @Override 
    public int getCount() { 
     // TODO Auto-generated method stub 
     return page_titles.length; 
    } 

    public CharSequence getPageTitle(int position) { 
     return page_titles[position]; 
    } 



} 

對不起,我的英語..

回答

0
pager = (ViewPager) findViewById(R.id.pager); 
pager.setOffscreenPageLimit(1); 

你的尋呼機組戲外頁數限制,默認爲所有頁面,你可能要2,使當前標籤旁邊的頁面將在您滑動之前加載。請參閱該方法的文檔以獲取更多信息

+0

在此之前,我已設置pager.setOffscreenPageLimit(3); cz我的標籤數量3.它使我的片段全部看起來加載在一起,但之前的片段不再加載。如果我設置了set pager.setOffscreenPageLimit(1);我以前的片段總是再次加載... 但我想突出點擊或集中片段正在加載,如果回前一個片段不再加載 – bukanamay

相關問題