把自定义表格又改进了一下,可以支持行合并。表格分为简单和复杂两种模式
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 =