我有一个问题,它需要很长的时间来加载数据,并显示只有当我滚动查看寻呼机。有几次我已经使用了asynctask,但是没有工作。换了标签后,我叫了同样的片段有人帮我吗??
Here, is first time loaded data
After changing tab call same fragment
这是我的viewpager适配器
public class AdapterCategoryViewPager extends FragmentPagerAdapter {
Context context;
private List<Fragment> fragmentList;
private List<Type> typeList;
public AdapterCategoryViewPager(FragmentManager fm, Context context, List<Fragment> fragmentList, List<Type> typeList) {
super(fm);
this.context = context;
this.fragmentList = fragmentList;
this.typeList = typeList;
}
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public CharSequence getPageTitle(int position) {
return typeList.get(position).getType().toString();
}
@Override
public int getCount() {
return fragmentList.size();
}
}
这是我在异步任务中调用的这个函数的分类片段
private void setData(View v)
{
addWomenCategory();
ll_list.removeView(v);
gridView.removeView(v);
gridView.setMode(PullToRefreshBase.Mode.PULL_FROM_END);
adapterCategory=new AdapterCategory(v.getContext(),categoryArrayList,height,width);
gridView.setAdapter(adapterCategory);
g=(GridView) gridView.getRefreshableView();
g.setHorizontalSpacing(h7);
g.setVerticalSpacing(h7);
// g.setEnabled(false);
gridView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<GridView>() {
@Override
public void onRefresh(final PullToRefreshBase<GridView> refreshView) {
gridView.postDelayed(new Runnable() {
@Override
public void run() {
refreshView.getLoadingLayoutProxy().setRefreshingLabel("Loding Data...");
refreshView.getLoadingLayoutProxy().setReleaseLabel("Refresh complete");
addWomenCategory();
adapterCategory.notifyDataSetChanged();
gridView.setRefreshing(false);
gridView.onRefreshComplete();
}
},2000);
}
});
}
这里是我的homeFragment,它实际上在数组列表中添加了fragments类别这个函数我在asynctask中也调用过
private void setData(View v)
{
addType();
pager.setOffscreenPageLimit(3);
adapterType=new AdapterType(typeArrayList,v.getContext(),height,width);
fragmentList.add(new FragmentListCategory());
fragmentList.add(new FragmentMenListCategory());
fragmentList.add(new FragmentKidListCategory());
fragmentList.add(new FragmentListCategory());
fragmentList.add(new FragmentMenListCategory());
fragmentList.add(new FragmentKidListCategory());
pager.setAdapter(new AdapterCategoryViewPager(getFragmentManager(),v.getContext(),fragmentList,typeArrayList));
tabs.setViewPager(pager);
setUpTabStrip(v);
}
最佳答案
我使用通用的imageloader库来显示图像,并且每次在适配器中初始化它的对象来解决这个问题我在主活动的oncreate()方法的整个应用程序中只初始化该配置对象一次