关于ExpandableListAdapter
来源:互联网 发布:图书管理系统php价格 编辑:程序博客网 时间:2024/06/05 06:36
package jannonx.com.myapplication;import android.database.DataSetObserver;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.view.ViewGroup;import android.widget.AbsListView;import android.widget.ExpandableListAdapter;import android.widget.ExpandableListView;import android.widget.ExpandableListView.OnChildClickListener;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends AppCompatActivity { ExpandableListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ExpandableListView) findViewById(R.id.list); final MyExpandableListAdapter adapter = new MyExpandableListAdapter(); listView.setAdapter(adapter); //为ExpandableListView的子列表单击事件设置监听器 listView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "你单击了:" + adapter.getChild(groupPosition, childPosition), Toast.LENGTH_LONG).show(); return true; } }); //创建ExpandableListAdapter方式二// ExpandableListAdapter adapter = new BaseExpandableListAdapter() {// int[] logos = new int[]{// R.drawable.fw02,// R.drawable.fw05,// R.drawable.fw06,// R.drawable.fw07// };// private String[] armTypes = new String[]{// "WORD", "EXCEL", "EMAIL", "PPT"// };// private String[][] arms = new String[][]{// {"文档编辑", "文档排版", "文档处理", "文档打印"},// {"表格编辑", "表格排版", "表格处理", "表格打印"},// {"收发邮件", "管理邮箱", "登录登出", "注册绑定"},// {"演示编辑", "演示排版", "演示处理", "演示打印"},// };//// @Override// public int getGroupCount() {// return armTypes.length;// }//// @Override// public int getChildrenCount(int groupPosition) {// return arms[groupPosition].length;// }//// @Override// public Object getGroup(int groupPosition) {// return armTypes[groupPosition];// }//// @Override// public Object getChild(int groupPosition, int childPosition) {// return arms[groupPosition][childPosition];// }//// @Override// public long getGroupId(int groupPosition) {// return groupPosition;// }//// @Override// public long getChildId(int groupPosition, int childPosition) {// return childPosition;// }//// @Override// public boolean hasStableIds() {// return true;// }//// @Override// public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {// LinearLayout ll = new LinearLayout(MainActivity.this);// ll.setOrientation(LinearLayout.HORIZONTAL);// ImageView logo = new ImageView(MainActivity.this);// logo.setImageResource(logos[groupPosition]);// logo.setPadding(36, 15, 0, 0);// ll.addView(logo);// TextView textView = getTextView();// textView.setText(getGroup(groupPosition).toString());// textView.setPadding(10, 0, 0, 0);// ll.addView(textView);// return ll;// }//// @Override// public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {// TextView textView = getTextView();// textView.setText(getChild(groupPosition, childPosition).toString());// return textView;// }//// @Override// public boolean isChildSelectable(int groupPosition, int childPosition) {// return true;// }//// @Override// public boolean areAllItemsEnabled() {// return false;// }//// @Override// public boolean isEmpty() {// return false;// }//// @Override// public void onGroupExpanded(int groupPosition) {//// }//// @Override// public void onGroupCollapsed(int groupPosition) {//// }//// @Override// public long getCombinedChildId(long groupId, long childId) {// return 0;// }//// @Override// public long getCombinedGroupId(long groupId) {// return 0;// }//// private TextView getTextView() {// AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 64);// TextView textView = new TextView(MainActivity.this);// textView.setLayoutParams(lp);// textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);// textView.setPadding(36, 0, 0, 0);// textView.setTextSize(20);// return textView;// }// };// listView.setAdapter(adapter); } class MyExpandableListAdapter implements ExpandableListAdapter { int[] logos = new int[]{ R.drawable.fw02, R.drawable.fw05, R.drawable.fw06, R.drawable.fw07 }; private String[] armTypes = new String[]{ "WORD", "EXCEL", "EMAIL", "PPT" }; private String[][] arms = new String[][]{ {"文档编辑", "文档排版", "文档处理", "文档打印"}, {"表格编辑", "表格排版", "表格处理", "表格打印"}, {"收发邮件", "管理邮箱", "登录登出", "注册绑定"}, {"演示编辑", "演示排版", "演示处理", "演示打印"}, }; private int[][] armsImage=new int[][]{ {R.drawable.fw07,R.drawable.fw06,R.drawable.fw05,R.drawable.fw02,}, {R.drawable.fw07,R.drawable.fw06,R.drawable.fw05,R.drawable.fw02,}, {R.drawable.fw07,R.drawable.fw06,R.drawable.fw05,R.drawable.fw02,}, {R.drawable.fw07,R.drawable.fw06,R.drawable.fw05,R.drawable.fw02,}, }; @Override public void registerDataSetObserver(DataSetObserver observer) { } @Override public void unregisterDataSetObserver(DataSetObserver observer) { } @Override public int getGroupCount() { return armTypes.length; } @Override public int getChildrenCount(int groupPosition) { return arms[groupPosition].length; } @Override public Object getGroup(int groupPosition) { return armTypes[groupPosition]; } @Override public Object getChild(int groupPosition, int childPosition) { return arms[groupPosition][childPosition]; } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { LinearLayout ll = new LinearLayout(MainActivity.this); ll.setOrientation(LinearLayout.HORIZONTAL); ImageView logo = new ImageView(MainActivity.this); logo.setImageResource(logos[groupPosition]); logo.setPadding(36, 15, 0, 0); ll.addView(logo); TextView textView = getTextView(); textView.setText(getGroup(groupPosition).toString()); textView.setPadding(10, 0, 0, 0); ll.addView(textView); return ll; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { LinearLayout ll=new LinearLayout(MainActivity.this); ll.setOrientation(LinearLayout.HORIZONTAL); ImageView imageView=new ImageView(MainActivity.this); imageView.setImageResource(armsImage[groupPosition][childPosition]); imageView.setPadding(50,15,0,0); ll.addView(imageView); TextView textView = getTextView(); textView.setText(getChild(groupPosition, childPosition).toString()); textView.setPadding(5,0,0,0); textView.setTextSize(18); ll.addView(textView); return ll; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEmpty() { return false; } @Override public void onGroupExpanded(int groupPosition) { } @Override public void onGroupCollapsed(int groupPosition) { } @Override public long getCombinedChildId(long groupId, long childId) { return 0; } @Override public long getCombinedGroupId(long groupId) { return 0; } private TextView getTextView() { AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 64); TextView textView = new TextView(MainActivity.this); textView.setLayoutParams(lp); textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); textView.setPadding(36, 0, 0, 0); textView.setTextSize(20); return textView; } }}
0 0
- 关于ExpandableListAdapter
- ExpandableListAdapter
- ExpandableListAdapter
- ExpandableListAdapter
- ExpandableListAdapter
- ~~~关于ExpandableListAdapter的一个比较二的问题,求解啊~~~
- ExpandableListAdapter适配器
- 数据适配器简介(ExpandableListAdapter)
- 万能ExpandableListAdapter适配器
- ExpandableListAdapter详细介绍
- ExpandableListAdapter二级菜单适配器
- 二级列表SimpleExpandableListAdapter ,ExpandableListAdapter
- 使用ExpandableListView和ExpandableListAdapter实现分组列表
- 入门篇ExpandableListAdapter(简易树形组件)
- 第24章:ExpandableListAdapter的用法
- Android7.0中文文档(API)-- ExpandableListAdapter
- 用ExpandableListAdapter在每个child列表前添加图片
- (自定义ListView控件)在ExpandableListAdapter中嵌套ListView
- 解决adb无法连接手机问题
- 个别VC6.0+用vs2012打开后调试提示系统找不到文件
- 10种最流行的国外博客程序
- Android color资源
- scala的sliding window的多种实现和benchMark
- 关于ExpandableListAdapter
- QT信号槽连接方式
- 微信开通检测无需等待准确高的软件
- 树莓派3中文环境设置
- 4473: [Jsoi2015]symmetry
- Android(RK平台)编译流程优化-----选择性内核编译
- Python小程序
- 微信小程序开发环境搭建
- mysql 5.7.14 下载安装、配置与使用详细教程