本例说明:
(1)修改onCreate方法:
ExpandableListView实例(一)_数据库增删改查处理和listitem点击长按处理
http://blog.csdn.net/lk_blog/article/details/7562987
ExpandableListView实例(二)_两种方式实现QQ中组后面显示子条目数量效果
http://blog.csdn.net/lk_blog/article/details/7563355
ExpandableListView实例(三)_实现QQ中"未分组"效果和"未分组"不可编辑删除功能
http://blog.csdn.net/lk_blog/article/details/7563371
源代码下载地址: http://download.csdn.net/detail/lk_blog/4299729
实现QQ中"未分组"效果和"未分组"不可编辑删除功能.
注:本文数据库处理使用框架AHibernate,可以灵活操作sqlite数据库,详见: http://blog.csdn.net/lk_blog/article/details/7455992
本文只介绍主要部分,更多细节看上一篇博客:http://blog.csdn.net/lk_blog/article/details/7562987
效果图:
主要代码:
修改studentDaoImpl:
package com.tgb.lk.demo.dao.impl; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.tgb.lk.ahibernate.dao.impl.BaseDaoImpl; import com.tgb.lk.demo.dao.StudentDao; import com.tgb.lk.demo.model.Student; import com.tgb.lk.demo.util.DBHelper; import com.tgb.lk.demo.util.GroupChild; import android.content.Context; //本文数据库处理引用jar包AHibernate处理. //AHibernate的详细使用教程示例地址: http://blog.csdn.net/lk_blog/article/details/7455992 //AHibernate源码交流地址: http://blog.csdn.net/lk_blog/article/details/7456125 //AHibernate jar包下载及源代码下载地址: http://download.csdn.net/detail/lk_blog/4222048 public class StudentDaoImpl extends BaseDaoImpl<Student> implements StudentDao { public StudentDaoImpl(Context context) { super(new DBHelper(context)); } //sql语句加入left,无论学生有没有班级属性都会查到结果中 public List<GroupChild> getData() { String sql = "select s._id sid,s.name sname,c._id cid,c.name cname from t_student s " + "left join t_classes c on s.classesid=c._id"; List<Map<String, String>> list = super.query2MapList(sql, null); List<GroupChild> retList = new ArrayList<GroupChild>(); //实现“未分组”功能。 GroupChild gc1 = new GroupChild(); gc1.setGroupId("0"); gc1.setGroupName("未分组"); retList.add(gc1); for (Map<String, String> map : list) { GroupChild gc = new GroupChild(); gc.setChildId(map.get("sid")); gc.setChildName(map.get("sname")); gc.setGroupId(map.get("cid") == null ? "0" : map.get("cid")); gc.setGroupName(map.get("cname") == null ? "未分组" : map .get("cname")); retList.add(gc); } return retList; } } 修改MainActivity.java:
(1)修改onCreate方法:
// 设置如果长按在"未分组"上时显示不可编辑并且不显示ContextMenu,优先响应OnItemLongClickListener后才会出来ContextMenu expList.setOnItemLongClickListener(itemLongClickListener);
(2)添加OnItemLongClickListener:
OnItemLongClickListener itemLongClickListener = new OnItemLongClickListener() { //在LongClickListener判断如果是第一个分组就取消ContextMenu注册. @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { toastShow("本组不可编辑和删除!"); unregisterForContextMenu(expList); } else { registerForContextMenu(expList); } return false; } };
ExpandableListView实例(一)_数据库增删改查处理和listitem点击长按处理
http://blog.csdn.net/lk_blog/article/details/7562987
ExpandableListView实例(二)_两种方式实现QQ中组后面显示子条目数量效果
http://blog.csdn.net/lk_blog/article/details/7563355
ExpandableListView实例(三)_实现QQ中"未分组"效果和"未分组"不可编辑删除功能
http://blog.csdn.net/lk_blog/article/details/7563371
源代码下载地址: http://download.csdn.net/detail/lk_blog/4299729