xw13782513621
江三木洛
2015-11-26 07:41
采纳率: 33.3%
浏览 1.4k

listview对不同item布局问题

listview中使用getItemViewType和getViewTypeCount设置不同的布局样式,但是我没看到在哪里设置type对应layout,那么为什么通过getItemViewType就知道是否存在这样的convertView?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • bdmh
    bdmh 2015-11-26 07:57
    已采纳

    getview中,根据getItemViewType的值,加载不同的布局

    点赞 评论
  • sl_18500
    小小Q_Forler 2015-11-26 08:27

    if(convertView == null){

    switch (type){

    case TALK_TYPE_YOU:

    convertView = inflater.inflate(R.layout.talk_item_you,parent,false);

    break;

    case TALK_TYPE_ME:

    convertView = inflater.inflate(R.layout.talk_item_me,parent,false);

    break;

    }

    holder = new ViewHolder();

    holder.talk_time = (TextView) convertView.findViewById(R.id.talk_time);

    holder.talk_icon = (ImageView) convertView.findViewById(R.id.talk_icon);

    holder.talk_man = (TextView) convertView.findViewById(R.id.talk_man);

    holder.talk_content = (TextView) convertView.findViewById(R.id.talk_content);

    convertView.setTag(holder);

    }else{

    holder = (ViewHolder) convertView.getTag();

    }

    点赞 评论
  • qq_27578023
    qq_27578023 2016-05-28 14:06

    if(convertView == null){

    switch (type){

    case TALK_TYPE_YOU:

    convertView = inflater.inflate(R.layout.talk_item_you,parent,false);

    break;

    case TALK_TYPE_ME:

    convertView = inflater.inflate(R.layout.talk_item_me,parent,false);

    break;

    }

    holder = new ViewHolder();

    holder.talk_time = (TextView) convertView.findViewById(R.id.talk_time);

    holder.talk_icon = (ImageView) convertView.findViewById(R.id.talk_icon);

    holder.talk_man = (TextView) convertView.findViewById(R.id.talk_man);

    holder.talk_content = (TextView) convertView.findViewById(R.id.talk_content);

    convertView.setTag(holder);

    }else{

    holder = (ViewHolder) convertView.getTag();

    }

    点赞 评论

相关推荐