package com.src.zhang.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseExpandableListAdapter;
import android.widget.Toast;
import android.widget.SimpleAdapter;
import android.widget.TextView;
/**
* @author Administrator
*
*/
public class ListViewAdapter extends BaseExpandableListAdapter implements
OnItemClickListener
{
public static final int ItemHeight = 30;// 每项的高度
public static final int PaddingLeft = 36;// 每项的高度
private int myPaddingLeft = 0;
// private MyGridView toolbarGrid;
private GridView toolbarGrid;
private String menu_toolbar_name_array[] = { "存储卡", "我的下载", "图书导入", "系统备份",
"系统恢复", "清除全部", "在线升级", "快速入门", "关于开卷", "退出系统", "在线升级", "快速入门",
"关于开卷", "退出系统", "关于开卷", "退出系统", "关于开卷", "退出系统", "关于开卷", "退出系统" };
private int menu_toolbar_image_array[] = { R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard, R.drawable.icon_sdcard,
R.drawable.icon_sdcard };
private List<TreeNode> treeNodes = new ArrayList<TreeNode>();
private Context parentContext;
private LayoutInflater layoutInflater;
static public class TreeNode
{
Object parent;
List<Object> childs = new ArrayList<Object>();
}
public ListViewAdapter(Context view, int myPaddingLeft)
{
parentContext = view;
this.myPaddingLeft = myPaddingLeft;
}
public List<TreeNode> GetTreeNode()
{
return treeNodes;
}
public void UpdateTreeNode(List<TreeNode> nodes)
{
treeNodes = nodes;
}
public void RemoveAll()
{
treeNodes.clear();
}
public Object getChild(int groupPosition, int childPosition)
{
return treeNodes.get(groupPosition).childs.get(childPosition);
}
public int getChildrenCount(int groupPosition)
{
return treeNodes.get(groupPosition).childs.size();
}
static public TextView getTextView(Context context)
{
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ItemHeight);
TextView textView = new TextView(context);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
return textView;
}
/**
* 可自定义ExpandableListView
*/
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent)
{
if (convertView == null)
{
layoutInflater = (LayoutInflater) parentContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.grid_activity, null);
toolbarGrid = (GridView)convertView.findViewById(R.id.gridView);
LayoutParams linearParams = (LinearLayout.LayoutParams)toolbarGrid.getLayoutParams(); // 取控件mGrid当前的布局参数
linearParams.width = menu_toolbar_name_array.length * (113) + 5;
toolbarGrid.setLayoutParams(linearParams);
toolbarGrid.setNumColumns(menu_toolbar_name_array.length);
toolbarGrid.setColumnWidth(114);
toolbarGrid.setStretchMode(GridView.NO_STRETCH);
toolbarGrid.setAdapter(getMenuAdapter(menu_toolbar_name_array,
menu_toolbar_image_array));// 设置菜单Adapter
toolbarGrid.setOnItemClickListener(this);
}
return convertView;
}
/**
* 可自定义list
*/
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
{
TextView textView = getTextView(this.parentContext);
textView.setText(getGroup(groupPosition).toString());
textView.setPadding(myPaddingLeft + PaddingLeft, 0, 0, 0);
return textView;
}
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
public Object getGroup(int groupPosition)
{
return treeNodes.get(groupPosition).parent;
}
public int getGroupCount()
{
return treeNodes.size();
}
public long getGroupId(int groupPosition)
{
return groupPosition;
}
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return true;
}
public boolean hasStableIds()
{
return true;
}
/**
* 构造菜单Adapter
*
* @param menuNameArray
* 名称
* @param imageResourceArray
* 图片
* @return SimpleAdapter
*/
private SimpleAdapter getMenuAdapter(String[] menuNameArray,
int[] imageResourceArray)
{
ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < menuNameArray.length; i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("itemImage", imageResourceArray[i]);
map.put("itemText", menuNameArray[i]);
data.add(map);
}
SimpleAdapter simperAdapter = new SimpleAdapter(parentContext, data,
R.layout.item_menu, new String[] { "itemImage", "itemText" },
new int[] { R.id.item_image, R.id.item_text });
return simperAdapter;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id)
{
Toast.makeText(parentContext, "当前选中的是:" + position, Toast.LENGTH_SHORT)
.show();
}
}

silvia0427
- 粉丝: 13
最新资源
- 采购电子商务平台(网上超市部分)操作手册.doc
- 工程进料台帐(QR7.4.1-05).docx
- 一号机深层搅拌桩原始记录表.doc
- 悬挑钢管脚手架在筒库顶板施工中的应用.doc
- 探讨信息技术与中职计算机专业课程整合.docx
- 基于正交试验设计下的卷积神经网络在图像识别上的研究与应用.docx
- 华科土木地基处理技术Chapter-5.ppt
- 毕业设计开题分析方案4-钢筋混凝土多层、多跨框架软件开发.doc
- C语言程序设计实习分析方案---学生信息管理系统.doc
- 企业组织结构设计与部门职能划分.doc
- 9001体系记录范本-表格-教年度教育培训计划表.doc
- 浅谈建筑装饰工程的投标报价和文件编制.doc
- 商务酒店暖通施工方案(精品工程项目).doc
- 单片机的智能充电器设计大学课程.doc
- EPC交钥匙项目合同.ppt
- 电缆沟砖砌体沟壁施工工艺及施工要点.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
前往页