自定义的ListView具有不同的行布局,根据Web服务的响应被夸大 [英] Custom ListView with different row layouts to be inflated depending on webservice response

查看:142
本文介绍了自定义的ListView具有不同的行布局,根据Web服务的响应被夸大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ListView。

I have ListView.

我有3套的看法:

  1. 的ImageView
  2. VideoView
  3. TextView中。

我有一个Web服务器返回的图片,视频和文字。因此,基于来自服务器的响应我想夸大该行的观点在列表视图。

I have a webserver which returns images, videos and texts. So based on the response from the server i would like to inflate the views for the row's in listview.

我知道使用自定义适配器膨胀的自定义布局。

I am aware of inflating a custom layout using a custom adapter.

我想知道如何使用自定义适配器膨胀的意见类型?

I would like to know how to inflate views types using a custom adapter?.

例如:

如果Web服务器返回的形象,夸大ImageView的。

If the webserver returns image, inflate imageview.

推荐答案

关联ID为每个Web服务响应0图像,1 - 对于文本和2的影片。在ArrayList中存储的ID。然后覆盖getItemViewType()和getViewTypeCount()。充气适当的意见getView()。

Associate each webservice response with ID 0-for Images, 1-for Texts and 2-for Videos. Store ID in a ArrayList. Then Override getItemViewType() and getViewTypeCount(). Inflate appropriate views in getView().

   @Override

    public int getItemViewType(int position) 

    {

    int type;

    if (ID.get(position)== 0){
        type = TYPE_ITEM1;  //type 0 for image
    } else if (ID.get(position) == 1){
        type = TYPE_ITEM2; //type 1 for text
    }else {
        type = TYPE_ITEM3; //type 2 for videos
    }
    return type;
    }
@Override
public int getViewTypeCount() {
    return 3;    //three different layouts to be inflated
}

这篇关于自定义的ListView具有不同的行布局,根据Web服务的响应被夸大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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