1

可能重复:
片段更改时如何更新视图?

有一个在此有 2 个片段的活动 前两个页面显示带有自定义列表视图的片段,这些视图是使用 AsyncTask 从服务器的 xml 构建的。但是,当应用程序运行时,只显示一个列表视图,其他页面只是空白

我可以用这个方法来更新这个寻呼机吗

public Object instantiateItem(View container, int position) {

我的适配器代码是

public class VpiAbsTestActivity extends SherlockFragmentActivity {


private static final String[] CONTENT = new String[] { "1","2"};

TestFragmentAdapter mAdapter;
 ViewPager mPager;
 PageIndicator mIndicator;



protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs);

mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);

mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
mIndicator.notifyDataSetChanged();
}



class TestFragmentAdapter extends FragmentPagerAdapter {        
private int mCount = CONTENT.length;

public TestFragmentAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {
    switch(position) {

    case 0:
        return new customlist();


    case 1:
        return new customlistnotuser();


    default:
        return null;

    }
}

@Override
public int getCount() {
    return mCount;
}


public CharSequence getPageTitle(int position) {
    return VpiAbsTestActivity.CONTENT[position %             VpiAbsTestActivity.CONTENT.length].toUpperCase();
}

 @Override
    public void destroyItem(View collection, int position, Object view) {
         ((ViewPager) collection).removeView((View) view);
    }

 }
4

0 回答 0