listView 多个item布局

简介:
复制代码
package kds.szkingdom.wo.android.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.szkingdom.common.android.base.Res;
import com.szkingdom.commons.lang.StringUtils;
import com.szkingdom.modeWO.android.phone.R;
import com.trevorpage.tpsvg.SVGView;
import com.trevorpage.tpsvg.SvgRes1;

public class IACTChatAdapter extends BaseAdapter
{
    private Context context;
    private List<IACTMsgBean> msgList;

    public IACTChatAdapter(Context c, List<IACTMsgBean> msgList)
    {
        this.context = c;
        this.msgList = msgList;
    }

    @Override
    public int getCount()
    {
        return msgList.size();
    }

    @Override
    public Object getItem(int position)
    {
        return msgList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int pos, View view, ViewGroup parent)
    {
        Holder holder = null;
        if (view == null)
        {
            holder = new Holder();
            LayoutInflater inflater = LayoutInflater.from(context);
            view = (View) inflater.inflate(R.layout.iact_chat_msg_item, null);
            holder.rl_item = (RelativeLayout) view
                    .findViewById(R.id.iact_chat_msg_item);
            holder.rl_left = (RelativeLayout) view
                    .findViewById(R.id.rl_iact_chat_msg_left);
            holder.rl_right = (RelativeLayout) view
                    .findViewById(R.id.rl_iact_chat_msg_right);
            holder.tv_left = (TextView) view.findViewById(R.id.tv_user_left);
            holder.tv_right = (TextView) view.findViewById(R.id.tv_user_right);
            holder.iv_left = (Button) view
                    .findViewById(R.id.iv_iact_user_left);
            holder.iv_right = (SVGView) view
                    .findViewById(R.id.iv_iact_user_right);
            holder.tv_time_left = (TextView) view
                    .findViewById(R.id.tv_iact_chat_msg_time_left);
            holder.tv_time_right = (TextView) view
                    .findViewById(R.id.tv_iact_chat_msg_time_right);
            holder.ll_left = (LinearLayout) view.findViewById(R.id.ll_left);
            holder.ll_right = (LinearLayout) view.findViewById(R.id.ll_right);
            view.setTag(holder);
        } else
        {
            holder = (Holder) view.getTag();
            holder.rl_right.setVisibility(View.GONE);
            holder.rl_left.setVisibility(View.GONE);
        }
        IACTMsgBean bean = msgList.get(pos);
        if(!StringUtils.isEmpty(bean.getFeedbackContent())){
            //客户端消息
            holder.rl_right.setVisibility(View.VISIBLE);
            holder.iv_right.setSVGRenderer(
                    SvgRes1.getSVGParserRenderer(context, 
                            R.drawable.kds_wo_svg_sender), null);
            holder.tv_right.setText(bean.getFeedbackContent());
            holder.tv_time_right.setText(bean.getFeedbackTime());
            holder.ll_right.setBackgroundDrawable(Res.getDrawable(R.drawable.kds_wo_png_backgroud_blue));
        }
        if(!StringUtils.isEmpty(bean.getReplyContent())){
            //服务器端消息
            holder.rl_left.setVisibility(View.VISIBLE);
            holder.iv_left.setBackgroundResource(R.drawable.kds_gphone_original);
        
            holder.tv_left.setText(bean.getReplyContent());
            holder.tv_time_left.setText(bean.getReplyTime());
            holder.ll_left.setBackgroundDrawable(
                    Res.getDrawable(R.drawable.kds_wo_png_background_white));
        }
        return view;
    }

    private class Holder
    {
        RelativeLayout rl_item;
        RelativeLayout rl_left;
        RelativeLayout rl_right;
        TextView tv_time_left;
        TextView tv_time_right;
        TextView tv_left;
        TextView tv_right;
        Button iv_left;
        SVGView iv_right;
        LinearLayout ll_left;
        LinearLayout ll_right;
    }

}
复制代码

 


本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5462220.html,如需转载请自行联系原作者

相关文章
ListView Item多布局的实现
ListView这个小节的最后一节,给大家带来的是ListView多布局Item的实现, 何为ListView Item多布局,打个比方,QQ这种聊天列表
121 0
|
API Android开发
ListView或GridView上添加能一起滚动的Button效果的解决思路
ListView或GridView上添加能一起滚动的Button效果的解决思路
|
Android开发
Android ListView的每个子Item如何设置高度
Android ListView的每个子Item如何设置高度
570 0
|
Android开发 数据格式 XML
ListView项(Item)的三种布局
转载自:ListView项(Item)的三种布局使用例子 List中的item布局有三种: 自定义的布局,使用了相对布局(RelativeLayout,见list_item.
759 0
|
Java Android开发
NestedScrollView嵌套RecyclerView最后一条item显示不全
NestedScrollView嵌套RecyclerView最后一条item显示不全 首先要在最外层的NestedScrollView配置属性 android:fillViewport="true": 然后在上层Ja...
8280 0
|
Android开发
RecyclerView的item的宽高问题
在创建viewholder传入的View时,如果不指定其viewgroup,就会出现宽高只包裹显示内容的问题。 View view = LayoutInflater.from(context).inflate(R.layout.test_test,null); 上面的做法就会出问题 改成这样就可以正常显示设置的宽高 View view = LayoutInflater.from(context).inflate(R.layout.test_test,parent,false); 那么还是有一个问题。
1312 0
|
索引
Android--listView中的button控件获取item的值
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/55253877 在listv...
1219 0
|
Android开发
Android ScrollView嵌套GridView导致GridView只显示一行item
Android ScrollView嵌套GridView导致GridView只显示一行item Android ScrollView在嵌套GridView时候,会导致一个问题发生:GridView只显示一行。
2310 0