首页>代码>Android客户端智能聊天图灵机器人demo>/TuLingDemo/src/com/stone/tulingdemo/MyAdapter.java
package com.stone.tulingdemo;

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.RelativeLayout;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {

	private List<ListData> listDatas;
	private Context context;
	private RelativeLayout layout;
	private String time;

	public MyAdapter(List<ListData> listDatas, Context context) {
		super();
		this.listDatas = listDatas;
		this.context = context;
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listDatas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(context);
		if(listDatas.get(position).getFlag() == ListData.RECEIVE){
			//加载系统说的话
			layout = (RelativeLayout) inflater.inflate(R.layout.leftitem, null);
		}
		if(listDatas.get(position).getFlag() == ListData.SEND){
			//加载自己说的话
			layout = (RelativeLayout) inflater.inflate(R.layout.rightitem, null);
		}
		TextView tv = (TextView) layout.findViewById(R.id.tv);
		TextView time = (TextView) layout.findViewById(R.id.time);
		tv.setText(listDatas.get(position).getContent());
		time.setText(listDatas.get(position).getTime());
		return layout;
	}

}
最近下载更多
GZW012345  LV8 2022年3月27日
李秋天  LV6 2021年12月21日
3089559272  LV11 2021年12月21日
fflzbb  LV1 2021年11月17日
iRichard1314  LV6 2021年4月22日
fengxiao  LV8 2020年12月29日
a566566  LV9 2020年12月27日
aaa5849310  LV25 2020年12月19日
sfdasfda  LV1 2020年12月13日
natism  LV9 2020年12月3日
最近浏览更多
3334004690  LV3 3月20日
学习112  LV2 2023年12月21日
hhhhhz  LV7 2023年11月14日
微信网友_6627705560322048  LV1 2023年8月30日
万紫怡  LV4 2023年6月15日
200171  LV9 2023年6月1日
202105013142  LV1 2023年5月2日
ajdgqd  LV3 2023年3月10日
annazhang  LV29 2023年2月17日
machunming  LV1 2023年2月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友