如何设置查看传呼机为每个清单项目传呼机、清单、如何设置、项目

2023-09-06 09:26:57 作者:冰封de薆=

我有一个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 ...