我正在尝试实现一个文章查看器,首先,它将使用滑动标签和ViewPager显示按类别划分的文章列表。
我从服务器中提取文章,并试图通过ContentProvider和CursorLoader将它们加载到UI。
为了实现上述结构,我遵循了this,它使用了ViewPager标签。
以下是兴趣点:
@Override
public Object instantiateItem(ViewGroup container, int position) {
// Inflate a new layout from our resources
View view = getActivity().getLayoutInflater().inflate(R.layout.article_list,
container, false);
// Add the newly created View to the ViewPager
container.addView(view);
switch (position) {
case 0:
Intent intent1 = new Intent(getActivity(), ArticleService.class);
intent1.putExtra(ArticleService.CATEGORY_EXTRA, 1);
getActivity().startService(intent1);
break;
case 1:
Intent intent2 = new Intent(getActivity(), ArticleService.class);
intent2.putExtra(ArticleService.CATEGORY_EXTRA, 2);
getActivity().startService(intent2);
break;
case 2:
Intent intent3 = new Intent(getActivity(), ArticleService.class);
intent3.putExtra(ArticleService.CATEGORY_EXTRA, 3);
getActivity().startService(intent3);
break;
case 3:
Intent intent4 = new Intent(getActivity(), ArticleService.class);
intent4.putExtra(ArticleService.CATEGORY_EXTRA, 4);
getActivity().startService(intent4);
break;
case 4:
Intent intent5 = new Intent(getActivity(), ArticleService.class);
intent5.putExtra(ArticleService.CATEGORY_EXTRA, 5);
getActivity().startService(intent5);
break;
}
// Return the View
return view;
}
正如您所看到的,我正在创建一个与不同文章类别相对应的不同请求,并且我打算将每个选项卡的结果内容显示在ListView中。计划是将CursorAdapter设置为ListView,但我以前从未使用过滑动标签。我将如何实施?
提前致谢。