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,如需转载请自行联系原作者