Android中使用ListView绘制自定义表格(3)

这篇博客介绍了如何在Android中使用ListView绘制自定义表格,特别强调了新增的复杂模式,该模式支持行合并。内容包括两种模式的说明,其中简单模式不支持行合并,而复杂模式则增加了这一功能。为了生成正确数据,博主建议使用简单的布局设计器来避免手动计算导致的错误。源码变更已在文中提及。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

把自定义表格又改进了一下,可以支持行合并。表格分为简单和复杂两种模式

1、简单模式就是《Android中使用ListView绘制自定义表格(2)》描述的方式。不支持行合并

2、复杂模式支持行列合并

1、基于上回上传的代码,改动文件如下

package csdn.danielinbiti.custometableview.item;

public class ItemCell {
	private String cellValue = "";//单元格的值
	private int cellSpan = 1; //单元格跨列
	private CellTypeEnum cellType = CellTypeEnum.LABEL; //单元格类型
	private int colNum = 0;  //单元格列号,从0开始
	private int rowNum = 0;//从0开始,每个item都从0开始
	private int rowSpan = 1;//单元格跨行
	//private int rowType = 0; //行类型
	
	private boolean isChange = false;//是否被编辑
	public ItemCell(String cellValue,CellTypeEnum cellType,int cellSpan){
		this.cellValue = cellValue;
		this.cellType = cellType;
		this.cellSpan = cellSpan;
	}
	public ItemCell(String cellValue, CellTypeEnum cellType){
		this(cellValue,cellType,1);
	}
	public int getColNum(){
		return this.colNum;
	}
//	public void setRowType(int rowType){
//		this.rowType = rowType;
//	}
//	public int getRowType(){
//		return this.rowType;
//	}
	public String getCellValue(){
		return cellValue;
	}
	public void setCellValue(String value){
		this.cellValue = value;
	}
	public CellTypeEnum getCellType(){
		return cellType;
	}
	public int getCellSpan(){
		return cellSpan;
	}
	public void setIsChange(boolean isChange){
		this.isChange = isChange;
	}
	public boolean getIsChange(){
		return this.isChange;
	}
	//设置行列位置,列根据前面列+rowspan数字累加后的值,rownum每行都从0开始
    public void setPos(int rowNum,int colNum,int rowSpan){
    	this.rowNum = rowNum;
    	this.colNum = colNum;
    	this.rowSpan = rowSpan;
    }
	public int getRowNum() {
		return rowNum;
	}
	public int getRowSpan() {
		return rowSpan;
	}
    public int getId(){
    	return this.rowNum * 10000 + this.rowSpan;
    }
}

CustomeTableItem.java

package csdn.danielinbiti.custometableview.item;

import java.util.ArrayList;
import java.util.HashMap;

import csdn.danielinbiti.custometableview.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class CustomeTableItem extends LinearLayout {
	private Context context = null;
	private boolean isRead = false;//是否只读
	private ArrayList<View> viewList = new ArrayList();//行的表格列表
	private HashMap<String,View> viewMap = new HashMap();//key为行列组合
	private int[] headWidthArr = null;//表头的列宽设置
	private String rowType = "0";//行的样式id
	private int rowHeight = 0;
	private boolean isSimple =
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值