package com.jqyd.adapter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import com.jqyd.app.MyApp;
import com.jqyd.manager.R;
public class MyAdapter extends BaseAdapter {
private LayoutInflater inflater;
private ArrayList<HashMap<String, String>> list;
private int param = 2;
private static HashMap<Integer, Boolean> isSelected;
private MyApp myApp;
public MyAdapter(ArrayList<HashMap<String, String>> list, Context context) {
super();
this.list = list;
this.inflater = LayoutInflater.from(context);
isSelected = new HashMap<Integer, Boolean>();
initDate();
}
public MyAdapter(ArrayList<HashMap<String, String>> list, Context context,
int param) {
super();
this.list = list;
this.inflater = LayoutInflater.from(context);
this.param = param;
isSelected = new HashMap<Integer, Boolean>();
myApp = (MyApp) context.getApplicationContext();
initDate();
}
private void initDate() {
for (int i = 0; i < list.size(); i++) {
getIsSelected().put(i, false);
}
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//System.out.println("param************"+param);
if (param == -1) {// 加载的列表,含有一个参数且包含图片
convertView = inflater.inflate(R.layout.lxr_list, null);
ImageView iv=(ImageView) convertView.findViewById(R.id.lxr_iv_image);
TextView textView1 = (TextView) convertView
.findViewById(R.id.lxr_tv_text);
HashMap<String, String> map = list.get(position);
iv.setBackgroundResource(android.R.drawable.ic_menu_myplaces);
textView1.setText(map.get("textView1"));
}else if (param == 1) {// 加载的列表,含有一个参数,白色背景
convertView = inflater.inflate(R.layout.splist, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
HashMap<String, String> map = list.get(position);
String state = map.get("state");
if(state != null && state.equals("1")){//公告通知
textView1.setText(Html.fromHtml(""+map.get("textView1")+"[<font color=red>!</font>]"));
}else{
textView1.setText(Html.fromHtml(map.get("textView1")));
}
} else if (param == 2) {// 加载的列表,含有两个参数
convertView = inflater.inflate(R.layout.commlist, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
TextView textView2 = (TextView) convertView
.findViewById(R.id.textView2);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
textView2.setText(Html.fromHtml(map.get("textView2")));
} else if (param == 3) {// 加载的列表,含有三个参数
convertView = inflater.inflate(R.layout.commlist3, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
TextView textView2 = (TextView) convertView
.findViewById(R.id.textView2);
TextView textView3 = (TextView) convertView
.findViewById(R.id.textView3);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
textView2.setText(map.get("textView2"));
textView3.setText(map.get("textView3"));
} else if (param == -3) {// 加载的列表,含有三个参数且包含图片
convertView = inflater.inflate(R.layout.user_list, null);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.imageId);
TextView textView2 = (TextView) convertView
.findViewById(R.id.textView1);
TextView textView3 = (TextView) convertView
.findViewById(R.id.textView2);
HashMap<String, String> map = list.get(position);
imageView.setImageResource(android.R.drawable.ic_menu_myplaces);
textView2.setText("名称:"+map.get("textView1"));
textView3.setText("地址:"+map.get("textView2"));
}else if (param == 4) {// 加载的列表,含有两个参数
convertView = inflater.inflate(R.layout.commlist2, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
TextView textView2 = (TextView) convertView
.findViewById(R.id.textView2);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
textView2.setText(map.get("textView2"));
} else if (param == 5) {// 加载的列表,含有三个参数,但包含一个复选框
convertView = inflater.inflate(R.layout.commlist4, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
CheckBox cb = (CheckBox) convertView.findViewById(R.id.select);
/*TextView textView2 = (TextView) convertView
.findViewById(R.id.textView2);*/
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
ArrayList<String> nameList = myApp.getLxrTelAndName();
ArrayList<String> tellist = myApp.getLxrTel();
Log.e("已经选择的", nameList.toString());
Boolean flag = false;
for(int n =0;n<nameList.size();n++){
String name = nameList.get(n);
String tel = tellist.get(n);
if(name.equals(map.get("textView1"))&&tel.equals(map.get("cid"))){
flag = true ;
}
}
if(flag){
cb.setChecked(true);
}
//textView2.setText(map.get("textView2"));
} else if (param == 6) {// 加载的列表,含有一个参数
convertView = inflater.inflate(R.layout.commlist5, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
}else if (param == 7) {// 加载的列表,含有两个参数,且改变字体颜色
convertView = inflater.inflate(R.layout.commlist, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
TextView textView2 = (TextView) convertView
.findViewById(R.id.textView2);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
String addtime = map.get("textView2");
addtime = addtime.split("-")[1]+"/"+addtime.split("-")[2];
if(map.get("state").equals("1")){
textView2.setText(Html.fromHtml(""+addtime+"[<font color=red>!</font>]"));
}else{
textView2.setText(Html.fromHtml(""+addtime+"[已读]"));
}
}else if (param == 8) {// 加载的列表,含有三个参数,但包含一个单选框
convertView = inflater.inflate(R.layout.commlist4, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
RadioButton rb = (RadioButton) convertView.findViewById(R.id.select_one);
CheckBox cb = (CheckBox) convertView.findViewById(R.id.select);
cb.setVisibility(CheckBox.GONE);
rb.setVisibility(RadioButton.VISIBLE);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
}else if (param == 9) {// 加载的列表,含有七个参数
convertView = inflater.inflate(R.layout.commlist6, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
TextView textView2 = (TextView) convertView
.findViewById(R.id.textView2);
TextView textView3 = (TextView) convertView
.findViewById(R.id.textView3);
TextView textView4 = (TextView) convertView
.findViewById(R.id.textView4);
TextView textView5 = (TextView) convertView
.findViewById(R.id.textView5);
TextView textView6 = (TextView) convertView
.findViewById(R.id.textView6);
TextView textView7 = (TextView) convertView
.findViewById(R.id.textView7);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
textView2.setText(map.get("textView2"));
textView3.setText(map.get("textView3"));
textView4.setText(map.get("textView4"));
textView5.setText(map.get("textView5"));
textView6.setText(map.get("textView6"));
textView7.setText(map.get("textView7"));
}else if (param == 10) {// 加载的列表,含有一个参数,黑色背景
convertView = inflater.inflate(R.layout.commlist8, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
}else if (param == 11) {// 加载的列表,含有七个参数
convertView = inflater.inflate(R.layout.commlist9, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.spid);
TextView textView2 = (TextView) convertView
.findViewById(R.id.spname);
TextView textView3 = (TextView) convertView
.findViewById(R.id.ggxh);
TextView textView4 = (TextView) convertView
.findViewById(R.id.unit);
TextView textView5 = (TextView) convertView
.findViewById(R.id.ckprice);
TextView textView6 = (TextView) convertView
.findViewById(R.id.saleprice);
TextView textView7 = (TextView) convertView
.findViewById(R.id.spnum);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("spid"));
textView2.setText(map.get("spname"));
textView3.setText(map.get("ggxh"));
textView4.setText(map.get("unit"));
textView5.setText(map.get("ckprice"));
textView6.setText(map.get("saleprice"));
textView7.setText(map.get("spnum"));
}else if (param == 12) {// 加载的列表,含有三个参数,单选框隐藏
convertView = inflater.inflate(R.layout.commlist4, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
RadioButton rb = (RadioButton) convertView.findViewById(R.id.select_one);
CheckBox cb = (CheckBox) convertView.findViewById(R.id.select);
cb.setVisibility(CheckBox.GONE);
rb.setVisibility(RadioButton.GONE);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
textView1.setTextColor(Color.BLACK);
}else if (param == 13) {// 加载的列表,含有三个参数,但包含一个单选框
convertView = inflater.inflate(R.layout.commlist4, null);
TextView textView1 = (TextView) convertView
.findViewById(R.id.textView1);
RadioButton rb = (RadioButton) convertView.findViewById(R.id.select_one);
CheckBox cb = (CheckBox) convertView.findViewById(R.id.select);
cb.setVisibility(CheckBox.GONE);
rb.setVisibility(RadioButton.VISIBLE);
HashMap<String, String> map = list.get(position);
textView1.setText(map.get("textView1"));
textView1.setTextColor(Color.BLACK);
rb.setChecked(getIsSelected().get(position));
}
return convertView;
}
private SimpleDateFormat SimpleDateFormat(String string) {
// TODO Auto-generated method stub
return null;
}
public HashMap<Integer, Boolean> getIsSelected() {
return isSelected;
}
public void setIsSelected(HashMap<Integer, Boolean> isSelected) {
MyAdapter.isSelected = isSelected;
}
}