package com.eyu.activity_test;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
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 ExpandableList extends Activity{
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
final ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
//设置组视图的图片
int[] logos = new int[] { R.drawable.wei, R.drawable.shu,R.drawable.wu};
//设置组视图的显示文字
private String[] generalsTypes = new String[] { "魏", "蜀", "吴" };
//子视图显示文字
private String[][] generals = new String[][] {
{ "夏侯惇", "甄姬", "许褚", "郭嘉", "司马懿", "杨修" },
{ "马超", "张飞", "刘备", "诸葛亮", "黄月英", "赵云" },
{ "吕蒙", "陆逊", "孙权", "周瑜", "孙尚香" }
};
//子视图图片
public int[][] generallogos = new int[][] {
{ R.drawable.xiahoudun, R.drawable.zhenji,
R.drawable.xuchu, R.drawable.guojia,
R.drawable.simayi, R.drawable.yangxiu },
{ R.drawable.machao, R.drawable.zhangfei,
R.drawable.liubei, R.drawable.zhugeliang,
R.drawable.huangyueying, R.drawable.zhaoyun },
{ R.drawable.lvmeng, R.drawable.luxun, R.drawable.sunquan,
R.drawable.zhouyu, R.drawable.sunshangxiang } };
//自己定义一个获得文字信息的方法
TextView getTextView() {
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(
ExpandableList.this);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setPadding(36, 0, 0, 0);
textView.setTextSize(20);
textView.setTextColor(Color.BLACK);
return textView;
}
//重写ExpandableListAdapter中的各个方法
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return generalsTypes.length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return generalsTypes[groupPosition];
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return generals[groupPosition].length;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return generals[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LinearLayout ll = new LinearLayout(
ExpandableList.this);
ll.setOrientation(0);
ImageView logo = new ImageView(ExpandableList.this);
logo.setImageResource(logos[groupPosition]);
logo.setPadding(50, 0, 0, 0);
ll.addView(logo);
TextView textView = getTextView();
textView.setTextColor(Color.BLACK);
textView.setText(getGroup(groupPosition).toString());
ll.addView(textView);
return ll;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LinearLayout ll = new LinearLayout(
ExpandableList.this);
ll.setOrientation(0);
ImageView generallogo = new ImageView(
ExpandableList.this);
generallogo
.setImageResource(generallogos[groupPosition][childPosition]);
ll.addView(generallogo);
TextView textView = getTextView();
textView.setText(getChild(groupPosition, childPosition)
.toString());
ll.addView(textView);
return ll;
}
@Override
public boolean isChildSelectable(int groupPosition,
int childPosition) {
// TODO Auto-generated method stub
return true;
}
};
ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.list);
expandableListView.setAdapter(adapter);
//设置item点击的监听器
expandableListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(
ExpandableList.this,
"你点击了" + adapter.getChild(groupPosition, childPosition),
Toast.LENGTH_SHORT).show();
return false;
}
});
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ExpandableList仿QQ聊天下拉列表
共54个文件
jpg:20个
png:12个
class:9个
4星 · 超过85%的资源 需积分: 13 46 下载量 116 浏览量
2012-08-16
16:06:53
上传
评论 1
收藏 423KB RAR 举报
温馨提示
本demo以三国杀Q版人物的素材,模仿了类似QQ聊天下拉列表的样式,并实现了简单的点击监听,比较简单,复杂的功能有待大家一起共同完善
资源推荐
资源详情
资源评论
收起资源包目录
ExpandableListDemo.rar (54个子文件)
ExpandableListDemo
bin
classes.dex 7KB
ExpandableList_Test.apk 148KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
wu.png 1KB
ic_launcher.png 4KB
shu.png 2KB
wei.png 2KB
drawable-mdpi
ic_launcher.png 2KB
classes
com
eyu
activity_test
R$layout.class 403B
R$id.class 391B
R$drawable.class 1KB
R$attr.class 349B
ExpandableList$2.class 2KB
R.class 552B
ExpandableList.class 1KB
R$string.class 436B
ExpandableList$1.class 4KB
resources.ap_ 141KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
huatuo.jpg 5KB
guojia.jpg 6KB
zhugeliang.jpg 6KB
sunshangxiang.jpg 5KB
default_blank.jpg 7KB
wu.png 2KB
zhouyu.jpg 7KB
ic_launcher.png 4KB
zhaoyun.jpg 6KB
machao.jpg 6KB
shu.png 2KB
yangxiu.jpg 5KB
wei.png 3KB
liubei.jpg 6KB
lvmeng.jpg 5KB
simayi.jpg 6KB
sunquan.jpg 6KB
zhenji.jpg 6KB
huangyueying.jpg 6KB
luxun.jpg 6KB
xiahoudun.jpg 7KB
zhangfei.jpg 6KB
lvbu.jpg 6KB
xuchu.jpg 6KB
values
strings.xml 192B
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 540B
assets
gen
com
eyu
activity_test
R.java 2KB
proguard.cfg 1KB
.settings
org.eclipse.core.resources.prefs 88B
src
com
eyu
activity_test
ExpandableList.java 5KB
.project 854B
.classpath 364B
project.properties 361B
AndroidManifest.xml 842B
共 54 条
- 1
梵谷
- 粉丝: 522
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页