NetworkImageView - 从php文件显示多个图像

时间:2022-10-31 10:02:02

I'm working in AndroidStudio using NetworkImageView, I have to display the images in the PHP file below (There are more than 2 of them but it would be too long to list here), in a ListView. I understand I should use GetImageUrl? In all the examples I found, they used an image url, but in this case what would I put there?

我在使用NetworkImageView的AndroidStudio中工作,我必须在下面的PHP文件中显示图像(其中有两个以上,但这里列出的时间太长了),在ListView中。我明白我应该使用GetImageUrl?在我发现的所有例子中,他们使用了一个图片网址,但在这种情况下,我会把它放在那里?

Or do I have to include image_url somewhere in the ImageLoader?

或者我必须在ImageLoader中的某处包含image_url吗?

{
    "image_url": "http://tashdarcy.com/menu/images/1.jpg",
    "record_id": 11868,
    "title": "Congratulations to John on EPSRC funding",
    "date": "08/12/2014",
    "short_info": "A new EPSRC grant has been awarded to Dr John Batchelor as part of a GBP 1.9M project entitled: Adaptive Assistive Rehabilitative Technology"
}

I have this in the xml file for the list items:

我在列表项的xml文件中有这个:

 <com.android.volley.toolbox.NetworkImageView
    android:id="@+id/imageUrl"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerCrop"/>

I have an imageLoader in another class

我在另一个类中有一个imageLoader

  public void onCreate() {
    super.onCreate();

    instance = this;

    reqQueue = Volley.newRequestQueue(getApplicationContext());

    imageLoader = new ImageLoader(reqQueue, new ImageLoader.ImageCache()
    {
        private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(20);

        public void putBitmap(String url, Bitmap bitmap) {
            mCache.put(url, bitmap);
        }
        public Bitmap getBitmap(String url) {
            return mCache.get(url);

Can you tell me how to implement it? I understand it needs to go in the getView of my list class?

你能告诉我如何实现它吗?我明白它需要进入我的列表类的getView?

1 个解决方案

#1


1  

I'm not too sure what your problem is....everything is explained in the link you posted.

我不太确定你的问题是什么......所有内容都在你发布的链接中解释。

  1. You need to parse that JSON into POJO object
  2. 您需要将该JSON解析为POJO对象

  3. Then, use that list of POJO objects to populate an ArrayAdapter that ultimately populates the ListView
  4. 然后,使用该POJO对象列表填充最终填充ListView的ArrayAdapter

In the ArrayAdapter you will set the individual NetworkImageView url using the setImageUrl method...for example, this is a code snippet of the getView method of the ArrayAdapter from the link you posted...

在ArrayAdapter中,您将使用setImageUrl方法设置单个NetworkImageView网址...例如,这是您发布的链接中ArrayAdapter的getView方法的代码片段...

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater vi = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.lv_picasa_row, null);
    }

    ViewHolder holder = (ViewHolder) v.getTag(R.id.id_holder);       

    if (holder == null) {
        holder = new ViewHolder(v);
        v.setTag(R.id.id_holder, holder);
    }        

    PicasaEntry entry = getItem(position);
    if (entry.getThumbnailUrl() != null) {
        holder.image.setImageUrl(entry.getThumbnailUrl(), mImageLoader);
    } else {
        holder.image.setImageResource(R.drawable.no_image);
    }

    holder.title.setText(entry.getTitle());

    return v;
}

to be more especific, here's the ArrayAdapter implementation...

更具体,这是ArrayAdapter实现......

https://github.com/ogrebgr/android_volley_examples/blob/master/src/com/github/volley_examples/misc/PicasaArrayAdapter.java

as you can see, you have full access to source code examples. This is how you set the image url...

如您所见,您可以完全访问源代码示例。这就是你设置图片网址的方式......

holder.image.setImageUrl(entry.getThumbnailUrl(), mImageLoader);

where image is your NetworkImageView. What isn't still clear?

其中image是您的NetworkImageView。什么还不清楚?

#1


1  

I'm not too sure what your problem is....everything is explained in the link you posted.

我不太确定你的问题是什么......所有内容都在你发布的链接中解释。

  1. You need to parse that JSON into POJO object
  2. 您需要将该JSON解析为POJO对象

  3. Then, use that list of POJO objects to populate an ArrayAdapter that ultimately populates the ListView
  4. 然后,使用该POJO对象列表填充最终填充ListView的ArrayAdapter

In the ArrayAdapter you will set the individual NetworkImageView url using the setImageUrl method...for example, this is a code snippet of the getView method of the ArrayAdapter from the link you posted...

在ArrayAdapter中,您将使用setImageUrl方法设置单个NetworkImageView网址...例如,这是您发布的链接中ArrayAdapter的getView方法的代码片段...

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null) {
        LayoutInflater vi = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.lv_picasa_row, null);
    }

    ViewHolder holder = (ViewHolder) v.getTag(R.id.id_holder);       

    if (holder == null) {
        holder = new ViewHolder(v);
        v.setTag(R.id.id_holder, holder);
    }        

    PicasaEntry entry = getItem(position);
    if (entry.getThumbnailUrl() != null) {
        holder.image.setImageUrl(entry.getThumbnailUrl(), mImageLoader);
    } else {
        holder.image.setImageResource(R.drawable.no_image);
    }

    holder.title.setText(entry.getTitle());

    return v;
}

to be more especific, here's the ArrayAdapter implementation...

更具体,这是ArrayAdapter实现......

https://github.com/ogrebgr/android_volley_examples/blob/master/src/com/github/volley_examples/misc/PicasaArrayAdapter.java

as you can see, you have full access to source code examples. This is how you set the image url...

如您所见,您可以完全访问源代码示例。这就是你设置图片网址的方式......

holder.image.setImageUrl(entry.getThumbnailUrl(), mImageLoader);

where image is your NetworkImageView. What isn't still clear?

其中image是您的NetworkImageView。什么还不清楚?