zoukankan      html  css  js  c++  java
  • 普通expandalistviewadapter的定义

    package com.hwtt.android.oa.adapter;
    
    import static com.hwtt.android.oa.constants.Constants.FROM;
    
    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.Gravity;
    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 android.widget.Toast;
    
    import com.hwtt.android.oa.activity.R;
    import com.hwtt.android.oa.activity.personal.NoteDetailsActivity;
    import com.hwtt.android.oa.activity.personal.ReviseNoteActivity;
    import com.hwtt.android.oa.asyntask.DelNoteAsyncTask;
    import com.hwtt.android.oa.bean.NoteInfo;
    import com.hwtt.android.oa.tool.MyExpanableListView;
    
    /**
     * 我的便签列表适配器
     * 
     * @author Administrator
     * 
     */
    public class MyNoteAdapter extends BaseExpandableListAdapter {
        Context mContext;
        private int groupResourceId;
        private int childResourceId;
        MyExpanableListView exlv_note;
        private ArrayList<NoteInfo> noteList; // 组数据
        public ArrayList<Boolean> ischeck = new ArrayList<Boolean>(); // 标记是否被选中
        private LayoutInflater inflater;
        private Handler mHandler;
    
        public MyNoteAdapter(Context mContext, int groupResourceId,
                int childResourceId, ArrayList<NoteInfo> noteList,
                MyExpanableListView exlv_note, Handler mHandler) {
            super();
            this.mContext = mContext;
            this.groupResourceId = groupResourceId;
            this.childResourceId = childResourceId;
            this.noteList = noteList;
            this.exlv_note = exlv_note;
            this.mHandler = mHandler;
            inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            for (int i = 0; i < noteList.size(); i++) {
                ischeck.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) {
            // TODO Auto-generated method stub
            TextView tvRead, tvFix, tvDelete;
            ViewHolder vh;
            if (convertView == null) {
                convertView = inflater.inflate(childResourceId, null);
                tvRead = (TextView) convertView
                        .findViewById(R.id.tv_notechild_look);
                tvFix = (TextView) convertView.findViewById(R.id.tv_notechild_fix);
                tvDelete = (TextView) convertView
                        .findViewById(R.id.tv_notechild_delect);
                vh = new ViewHolder();
                vh.setTvRead(tvRead);
                vh.setTvFix(tvFix);
                vh.setTvDelete(tvDelete);
                convertView.setTag(vh);
    
            } else {
                vh = (ViewHolder) convertView.getTag();
                tvRead = vh.getTvRead();
                tvFix = vh.getTvFix();
                tvDelete = vh.getTvDelete();
            }
            // 修改申请
            tvFix.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
    
                    intent.setClass(mContext, ReviseNoteActivity.class);
                    intent.putExtra(FROM, noteList.get(groupPosition));
                    mContext.startActivity(intent);
    
                }
            });
            // 查看申请详情
            tvRead.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.setClass(mContext, NoteDetailsActivity.class);
    
                    intent.putExtra(FROM, noteList.get(groupPosition)); // 判断是否显示审批按钮区域,因为假单申请详情和假单审批详情共用一个layout
                    mContext.startActivity(intent);
                }
            });
            // 删除
            tvDelete.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    AlertDialog dialog;
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
                            .setTitle(R.string.dialog_point).setMessage(
                                    R.string.dialog_suredel).setPositiveButton(
                                    R.string.dialog_sure,
                                    new DialogInterface.OnClickListener() {
    
                                        @Override
                                        public void onClick(DialogInterface dialog,
                                                int which) {
                                            exlv_note.settips(mContext
                                                    .getResources().getString(
                                                            R.string.message_del));
                                            exlv_note.showHeaderView();
                                            exlv_note
                                                    .settips(mContext
                                                            .getResources()
                                                            .getString(
                                                                    R.string.message_refresh));
                                            new DelNoteAsyncTask(mHandler,
                                                    noteList.get(groupPosition)
                                                            .getNoteID(),
                                                    groupPosition).execute();
                                            exlv_note.collapseGroup(groupPosition);
                                        }
                                    }).setNegativeButton(R.string.dialog_cannl,
                                    null);
                    dialog = builder.create();
                    dialog.show();
    
                }
            });
    
            return convertView;
        }
    
        @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 noteList.get(groupPosition);
        }
    
        @Override
        public int getGroupCount() {
            // TODO Auto-generated method stub
            return noteList.size();// 设置listview显示几条信息
        }
    
        @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) {
            // TODO Auto-generated method stub
            String name, time = null; // 便签标题,便签时间
            TextView tvName, tvTime;
            CheckBox cb = null;
            RelativeLayout rl_01;
            ViewHolder vh;
            NoteInfo info = noteList.get(groupPosition);
            if (convertView == null) {
                convertView = inflater.inflate(groupResourceId, null);
                rl_01 = (RelativeLayout) convertView.findViewById(R.id.rl_01);
                tvName = (TextView) convertView.findViewById(R.id.tv_name);
                tvTime = (TextView) convertView.findViewById(R.id.tv_time);
    
                cb = (CheckBox) convertView.findViewById(R.id.cbox_note);
    
                vh = new ViewHolder();
                vh.setTvName(tvName);
                vh.setTvTime(tvTime);
                vh.setCb(cb);
                vh.setRl_01(rl_01);
                convertView.setTag(vh);
    
            } else {
                vh = (ViewHolder) convertView.getTag();
                tvName = vh.getTvName();
                tvTime = vh.getTvTime();
                rl_01 = vh.getRl_01();
                cb = vh.getCb();
            }
            name = info.getNoteName(); // 获取便签标题
            time = info.getNoteTime(); // 获取便签时间
    
            tvName.setText(name);
            tvTime.setText(time);
    
            cb.setChecked(ischeck.get(groupPosition));
            cb.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    if (ischeck.get(groupPosition)) {
    
                        ischeck.set(groupPosition, false);
                    } else {
    
                        ischeck.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 true;
        }
    
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            // TODO Auto-generated method stub
            return true;
        }
    
        // 提示信息
        public static void Info(String message, Context context) {
            Toast toast = Toast.makeText(context, message, 1);
            toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
            toast.show();
        }
    
        /**
         * 存储控件变量
         * 
         * @author Administrator
         * 
         */
        private class ViewHolder {
            TextView tvName, tvTime;
            TextView tvRead, tvFix, 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 getTvFix() {
                return tvFix;
            }
    
            public void setTvFix(TextView tvFix) {
                this.tvFix = tvFix;
            }
    
            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 getTvName() {
                return tvName;
            }
    
            public void setTvName(TextView tvName) {
                this.tvName = tvName;
            }
    
            public TextView getTvTime() {
                return tvTime;
            }
    
            public void setTvTime(TextView tvTime) {
                this.tvTime = tvTime;
            }
    
            public RelativeLayout getRl_01() {
                return rl_01;
            }
    
            public void setRl_01(RelativeLayout rl_01) {
                this.rl_01 = rl_01;
            }
        }
    }
  • 相关阅读:
    YUM安装MySQL 8.0
    linux 设置 别名 全局命令
    2018.3.12校内互测总结-生成函数-bitset-二次剩余
    Dirichlet 前缀和与快速莫比乌斯变换(FMT)
    CSP-S2 赛后总结
    概率和期望
    【题解】[洛谷 P4396 / bzoj 3236] 作业【莫队 分块 根号平衡】
    【题解】[LOJ 2736] 「JOISC 2016 Day 3」回转寿司【分块 堆】
    【题解】[UOJ 228] 基础数据结构练习题【线段树 均摊数据结构】
    【题解】[Codeforces 438D] The Child and Sequence【线段树 均摊数据结构】
  • 原文地址:https://www.cnblogs.com/ct732003684/p/2961832.html
Copyright © 2011-2022 走看看