package com.hwtt.android.oa.adapter.myapply; import java.util.ArrayList; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Handler; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.RelativeLayout; import android.widget.TextView; import com.hwtt.android.oa.activity.R; import com.hwtt.android.oa.activity.mytodeal.DetailsHolidayActivity; import com.hwtt.android.oa.asyntask.myapply.DelApplyAsynTask; import com.hwtt.android.oa.bean.deal.HolidayInfo; import com.hwtt.android.oa.constants.Constants; import com.hwtt.android.oa.tool.MyExpanableListView; import com.hwtt.android.oa.tool.MyProgressDialog; /** * 假单申请列表适配器 * * @author Administrator * */ public class HolidayApplyElvAdapter extends BaseExpandableListAdapter { private Context context; private int groupResourceId; private int childResourceId; private ArrayList<HolidayInfo> groupData; // 组数据 private MyExpanableListView elv; private LayoutInflater inflater; private MyProgressDialog progressDialog; private Handler mHandler; public ArrayList<Boolean> isCheckList = new ArrayList<Boolean>(); // 保存checkbox的点击状态 public HolidayApplyElvAdapter(Context context, int groupResourceId, int childResourceId, ArrayList<HolidayInfo> groupData, MyExpanableListView elv, MyProgressDialog progressDialog, Handler mHandler) { super(); this.context = context; this.groupResourceId = groupResourceId; this.childResourceId = childResourceId; this.groupData = groupData; this.elv = elv; this.progressDialog = progressDialog; this.mHandler = mHandler; inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // 初始化 ischeck for (int i = 0; i < groupData.size(); i++) { isCheckList.add(false); } } @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return null; } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return childPosition; } @Override public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { TextView tvRead, tvDelete; ViewHolder vh; if (convertView == null) { convertView = inflater.inflate(childResourceId, null); tvRead = (TextView) convertView.findViewById(R.id.tvRead); tvDelete = (TextView) convertView.findViewById(R.id.tvDelete); vh = new ViewHolder(); vh.setTvRead(tvRead); vh.setTvDelete(tvDelete); convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); tvRead = vh.getTvRead(); tvDelete = vh.getTvDelete(); } // 查看申请详情 tvRead.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(context, DetailsHolidayActivity.class); intent.putExtra(Constants.FROM, Constants.MY_APPLY); // 假单申请详情和假单待办详情的布局不同 intent.putExtra("id", groupData.get(groupPosition).getId());// 传递申请编号 context.startActivity(intent); } }); // 删除 tvDelete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final ArrayList<Integer> listGId = new ArrayList<Integer>(); final ArrayList<String> listApplyId = new ArrayList<String>(); AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(context) .setTitle("温馨提示").setMessage("确定要删除该项吗?") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // progressDialog.show(); elv.settips("正在删除..."); elv.showHeaderView(); elv.settips("正在刷新..."); listGId.add(groupPosition); listApplyId.add(groupData.get( groupPosition).getId()); new DelApplyAsynTask(context, mHandler, listGId, "0") .execute(listApplyId); } }).setNegativeButton("取消", null); dialog = builder.create(); dialog.show(); } }); return convertView; } /** * 获取当前点击开的组ID * * @return */ private int getExpandedGroupId() { int seletedPos = 0; // 判断点击的组ID for (int i = 0; i < groupData.size(); i++) { if (elv.isGroupExpanded(i)) { seletedPos = i; break; } } return seletedPos; } @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return 1; } @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return groupData.get(groupPosition); } @Override public int getGroupCount() { // TODO Auto-generated method stub return groupData.size(); } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return groupPosition; } @Override public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String time, type, state, holidaytime = null; // 申请类型,申请时间,审批进度,休假时数 TextView tvTime, tvPrompt, tvType, tvPrompt3, tv_Time, tvState; RelativeLayout rl_01; CheckBox cb = null; ViewHolder vh; HolidayInfo info = groupData.get(groupPosition); if (convertView == null) { convertView = inflater.inflate(groupResourceId, null); rl_01 = (RelativeLayout) convertView.findViewById(R.id.rl_01); tvTime = (TextView) convertView.findViewById(R.id.tvTime);// 申请时间 tvState = (TextView) convertView.findViewById(R.id.tvState);// 状态 tv_Time = (TextView) convertView.findViewById(R.id.tv_Time);// 休假时数 tvPrompt = (TextView) convertView.findViewById(R.id.tvRandomPrompt); tvPrompt3 = (TextView) convertView.findViewById(R.id.tvPrompt3); tvType = (TextView) convertView.findViewById(R.id.tvRandom); cb = (CheckBox) convertView.findViewById(R.id.cbApply); vh = new ViewHolder(); vh.setTvTime(tvTime); vh.setTv_Time(tv_Time); vh.setTvState(tvState); vh.setTvPrompt(tvPrompt); vh.setTvPrompt3(tvPrompt3); vh.setTvType(tvType); vh.setCb(cb); vh.setRl_01(rl_01); convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); tvTime = vh.getTvTime(); tv_Time = vh.getTv_Time(); tvState = vh.getTvState(); tvPrompt = vh.getTvPrompt(); tvPrompt3 = vh.getTvPrompt3(); tvType = vh.getTvType(); rl_01 = vh.getRl_01(); cb = vh.getCb(); } time = info.getApplicationDate(); // 获取申请时间 holidaytime = info.getHolidayTime();// 获取休假时数 type = info.getType(); // 获取假单类型描述 state = info.getState();// 获取状态 tvState.setText(state); tvTime.setText(time); tv_Time.setText(holidaytime); tvPrompt.setText("类型:"); tvPrompt3.setText("休假时数:"); tvType.setText(type); cb.setChecked(isCheckList.get(groupPosition)); cb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isCheckList.get(groupPosition)) { isCheckList.set(groupPosition, false); } else { isCheckList.set(groupPosition, true); } } }); if (!isExpanded) { rl_01.setBackgroundResource(R.drawable.default_item_bg); } else { rl_01.setBackgroundResource(R.drawable.ext_item_bg); } return convertView; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return false; } /** * 存储控件变量 * * @author Administrator * */ private class ViewHolder { TextView tvTime, tvPrompt, tvType, tvPrompt3, tv_Time, tvState; TextView tvRead, tvDelete; CheckBox cb; RelativeLayout rl_01; public ViewHolder() { super(); // TODO Auto-generated constructor stub } public TextView getTvRead() { return tvRead; } public void setTvRead(TextView tvRead) { this.tvRead = tvRead; } public TextView getTvDelete() { return tvDelete; } public void setTvDelete(TextView tvDelete) { this.tvDelete = tvDelete; } public CheckBox getCb() { return cb; } public void setCb(CheckBox cb) { this.cb = cb; } public TextView getTvTime() { return tvTime; } public void setTvTime(TextView tvTime) { this.tvTime = tvTime; } public TextView getTvType() { return tvType; } public void setTvType(TextView tvType) { this.tvType = tvType; } public TextView getTvPrompt() { return tvPrompt; } public void setTvPrompt(TextView tvPrompt) { this.tvPrompt = tvPrompt; } public RelativeLayout getRl_01() { return rl_01; } public void setRl_01(RelativeLayout rl_01) { this.rl_01 = rl_01; } public TextView getTvPrompt3() { return tvPrompt3; } public void setTvPrompt3(TextView tvPrompt3) { this.tvPrompt3 = tvPrompt3; } public TextView getTv_Time() { return tv_Time; } public void setTv_Time(TextView tvTime) { tv_Time = tvTime; } public TextView getTvState() { return tvState; } public void setTvState(TextView tvState) { this.tvState = tvState; } } }