Custom ListView with different row layouts to be inflated depending on webservice response

冷暖自知 提交于 2019-12-02 13:43:28

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!