package com.jxufe.treebutton;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class ButtonTreeBaseAdapter extends BaseAdapter {
private LayoutInflater mInflater;
// private List<Map<String, Object>> mData; //mData包含treepoint与复选框checkBox
private List<ButtonTreePoint> mTreeBoyList; // 树中仅可见的节点数据列表
private List<ButtonTreePoint> nodes; // 树中所有的数据节点列表
private Bitmap mIconCollapse;
private Bitmap mIconExpand;
private TreeButtonListener treeButtonListener ;
public static int static_count = 0;
public String tag = "in ButtonTreeBaseAdapter";
//构造函数
public ButtonTreeBaseAdapter(Context context,
List<ButtonTreePoint> mTreeBoyList, List<ButtonTreePoint> nodes) {
super();
this.mInflater = LayoutInflater.from(context);
this.mTreeBoyList = mTreeBoyList;
this.nodes = nodes;
mIconCollapse = BitmapFactory.decodeResource(context.getResources(),
R.drawable.outline_list_collapse);
mIconExpand = BitmapFactory.decodeResource(context.getResources(),
R.drawable.outline_list_expand);
}
public int getCount() {
// TODO Auto-generated method stub
return mTreeBoyList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ButtonTreePoint point = mTreeBoyList.get(position);
ViewHolderButton holder = new ViewHolderButton();
convertView = mInflater.inflate(R.layout.tree_button_listview, null);
//holder映射
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
holder.title = (TextView) convertView.findViewById(R.id.textView1);
holder.button = (Button) convertView.findViewById(R.id.button1);
//holder设置
holder.title.setText(point.getOutlineTitle());
holder.button.setFocusable(false);
holder.button.setText(mTreeBoyList.get(position).getButtonName().toString());
convertView.setTag(holder);
// 根据当前节点级别设置缩进
int level = point.getLevel();
holder.icon.setPadding(20 * (level + 1), holder.icon.getPaddingTop(),
0, holder.icon.getPaddingBottom());
// 根据当前节点是否有子节点及是否展开,设置节点图标状态
if (point.isMhasChild() && (point.isExpanded() == false)) {
holder.icon.setImageBitmap(mIconCollapse);
holder.icon.setVisibility(View.VISIBLE);
} else if (point.isMhasChild() && (point.isExpanded() == true)) {
holder.icon.setImageBitmap(mIconExpand);
holder.icon.setVisibility(View.VISIBLE);
} else if (!point.isMhasChild()) {
holder.icon.setImageBitmap(mIconCollapse);
holder.icon.setVisibility(View.INVISIBLE);
}
//对button进行设置和监听
treeButtonListener = new TreeButtonListener(mInflater,position,mTreeBoyList);
holder.button.setOnClickListener(treeButtonListener);
return convertView;
}
public class ViewHolderButton {
public ImageView icon;
public TextView title;
public Button button;
}
}
class TreeButtonListener implements Button.OnClickListener {
private LayoutInflater mInflater;
private int position;
private List<ButtonTreePoint> mTreeBoyList;
public TreeButtonListener(LayoutInflater mInflater, int position,
List<ButtonTreePoint> mTreeBoyList) {
super();
this.mInflater = mInflater;
this.position = position;
this.mTreeBoyList = mTreeBoyList;
}
public void onClick(View v) {
Toast.makeText( mInflater.getContext(), "监听成功",Toast.LENGTH_SHORT).show();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
android树,带图标、文字、按钮例子
共36个文件
class:12个
png:6个
xml:6个
4星 · 超过85%的资源 需积分: 13 73 下载量 83 浏览量
2011-08-15
15:18:11
上传
评论
收藏 466KB ZIP 举报
温馨提示
在android平台上用ListView和BaseAdapter实现的一颗完美带button的树
资源推荐
资源详情
资源评论
收起资源包目录
ButtonTree.zip (36个子文件)
ButtonTree
.project 846B
default.properties 362B
bin
ButtonTree.apk 151KB
com
jxufe
treebutton
R$string.class 433B
R$layout.class 444B
R$drawable.class 1KB
ButtonTreeActivity.class 4KB
TreePoint.class 2KB
ButtonTreeBaseAdapter.class 4KB
R.class 545B
ButtonTreeBaseAdapter$ViewHolderButton.class 722B
ButtonTreePoint.class 2KB
R$attr.class 346B
R$id.class 489B
TreeButtonListener.class 1KB
resources.ap_ 144KB
classes.dex 11KB
proguard.cfg 1KB
AndroidManifest.xml 692B
src
com
jxufe
treebutton
ButtonTreePoint.java 1KB
ButtonTreeActivity.java 3KB
ButtonTreeBaseAdapter.java 4KB
TreePoint.java 2KB
res
values
color.xml 984B
strings.xml 179B
layout
tree_button_listview.xml 2KB
main.xml 1KB
drawable-ldpi
icon.png 2KB
drawable-hdpi
control_unit_style18.xml 2KB
bg3.png 132KB
outline_list_expand.png 3KB
outline_list_collapse.png 3KB
icon.png 4KB
drawable-mdpi
icon.png 3KB
.classpath 280B
gen
com
jxufe
treebutton
R.java 2KB
assets
共 36 条
- 1
awen_PC
- 粉丝: 27
- 资源: 42
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页