如何设置查看传呼机为每个清单项目 [英] How to set View Pager for each item of a List

查看:105
本文介绍了如何设置查看传呼机为每个清单项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序的项目清单,我要每个项目要在页面上。问题是每个项目设定一个布局,从一个独特的URL下载其图像的ImageView的。这是可能的实现以及如何请?

I have a List of items in an android app , and i want each item to be on a page . the problem is each item sets a layout with an imageview which downloads its image from a unique url. Is this possible to implement and how please ?

需要帮助(任何形式)

推荐答案

每个页面应该是一个片段,这取决于你的项目对象,你可能想实现的 Parcelable 并通过你的对象作为参数传递给你的片段,像这样:

Each page should be a Fragment, depending on your item object, you may want to implement Parcelable and pass your object as an argument to your Fragment, like so :

在您的FragmentPagerAdapter:

in your FragmentPagerAdapter :

@Override
public Fragment getItem(int position) { 
    PageFragment fragment = new PageFragment();
    Bundle bundle = new Bundle();
    bundle.putParcelable("ARGUMENT_KEY_NAME", itemObjectsList.get(position));
    fragment.setArguments(bundle);
    return fragment;
}

和在片段的code,看了你的对象,像这样:

and in your Fragment's code, read your object like so :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = this.getArguments();
    Item item = bundle.getParcelable("ARGUMENT_KEY_NAME");
    // do things with your Item object
}

另外,如果您的项目目标过大,或者其他任何原因,你不能轻易地通过整个对象以捆绑,你可以只通过在碎片的相关信息被创建,即文字和图片网址等等...

Alternatively, if your item object is too large or if for any other reason you can't easily pass the whole object in a Bundle, you could just pass in the relevant info for the Fragment to be created, i.e. text and image urls etc ...

这篇关于如何设置查看传呼机为每个清单项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆