Android中使用ListView繪制自定義表格技巧分享
更新時(shí)間:2013年06月04日 16:18:05 作者:
使用ListView繪制自定義的表格有朋友嘗試過(guò)沒(méi)有,下面為大家分享下要實(shí)現(xiàn)下圖的效果有幾個(gè)方面,參照著這幾點(diǎn)做了個(gè)簡(jiǎn)單的實(shí)現(xiàn)不是問(wèn)題好了,話不多說(shuō)看代碼
先上一下可以實(shí)現(xiàn)的效果圖
要實(shí)現(xiàn)的效果有幾方面
1、列不固定:可以根據(jù)數(shù)據(jù)源的不同生成不同的列數(shù)
2、表格內(nèi)容可以根據(jù)數(shù)據(jù)源的定義合并列
3、要填寫(xiě)的單元格可以選擇自定義鍵盤(pán)還是系統(tǒng)鍵盤(pán)
奔著這三點(diǎn),做了個(gè)簡(jiǎn)單的實(shí)現(xiàn),把源碼貼一下(因?yàn)樵擖c(diǎn)是主界面中的一部分,不便于放整個(gè)Demo)
自定義適配器,CallBackInterface是自定義的回調(diào)接口,這里定義回調(diào)是因?yàn)閿?shù)據(jù)輸入時(shí)需要及時(shí)保存
public class SiteDetailViewAdapter extends BaseAdapter implements CallBackInterface{
private Context context;
private LayoutInflater inflater;
private ArrayList<HashMap<String,Object>> lists;
private KeyBoard keyBoard = null;//自定義鍵盤(pán)
private ListView listView = null;
private boolean isReadOnly = false;//是否是瀏覽狀態(tài)
private String[] arrCellType = null;
private int[] arrHeadWidth = null;//每列寬度
public SiteDetailViewAdapter(Context context, ArrayList<HashMap<String,Object>> lists
,KeyBoard keyBoard,ListView listView,boolean isReadOnly
,int[] arrHeadWidth) {
super();
this.context = context;
this.lists = lists;
inflater = LayoutInflater.from(context);
this.keyBoard = keyBoard;
this.listView = listView;
this.isReadOnly = isReadOnly;
this.arrHeadWidth = arrHeadWidth;
this.listView.setAdapter(this);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return lists.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int index, View view, ViewGroup arg2) {
HashMap map = lists.get(index);
String type = (String)map.get("rowtype");
ArrayList<ItemCell> itemCells = new ArrayList();
//String cellValue,String cellKey,long cellType,int cellInRow,int cellSpan
ItemCell itemCellXuHao = new ItemCell((index+1)+"","-1",1,-1,1);
itemCells.add(itemCellXuHao);
for(int i=0;i<map.size()-1;i++){
ItemCell itemCell = (ItemCell)map.get(i+"");
itemCells.add(itemCell);
}
//性能優(yōu)化后需要放開(kāi)注釋danielinbiti
if(view == null||view!=null&&!((ListItemCustom)view.getTag()).getType().equals(type)){
view = inflater.inflate(R.layout.customel_list_item, null);
ListItemCustom itemCustom = (ListItemCustom)view.findViewById(R.id.custome_item);
itemCustom.buildItem(type, context, isReadOnly,arrHeadWidth,itemCells,index
,this.listView,this.keyBoard,this);
view.setTag(itemCustom);
}else{
ListItemCustom itemCustom = (ListItemCustom)view.getTag();
itemCustom.refreshData(itemCells,index);
}
if(index%2 == 0){
view.setBackgroundColor(Color.argb(250 , 255 , 255 , 255 ));
}else{
view.setBackgroundColor(Color.argb(250 , 224 , 243 , 250 ));
}
return view;
}
@Override
public boolean exectueMethod(Object params) {
String[] arr = (String[])params;
HashMap map = lists.get(Integer.parseInt(arr[0]));
ItemCell itemCell = (ItemCell)map.get(arr[1]);
itemCell.setCellValue(arr[2]);
itemCell.setIsChange(true);
return false;
}
ListView每行的布局,內(nèi)部代碼是有冗余的,因?yàn)槭荄emo,所以先以效果未準(zhǔn),未進(jìn)行代碼重構(gòu),注意不能往ListItemCustom中傳入每行的Map來(lái)進(jìn)行值得獲取或者輸入更新等操作,因?yàn)镸ap是按地址方式,再結(jié)合ListView的繪制方式,最終的map不是你想象的map。
public class ListItemCustom extends LinearLayout{
public ListItemCustom(Context context){
super(context);
}
public ListItemCustom(Context context, AttributeSet attrs) {
super(context, attrs);
}
private String type = "-1";
private Context context = null;
private boolean isRead = false;
private int[] headWidthArr = null;
private ListView listView = null;
private KeyBoard keyBoard = null;
private int orderNum = -1;
private ArrayList<View> viewList = new ArrayList();
private int rowNum = -1;
private CallBackInterface callBack = null;
public void buildItem(String type,Context context,boolean isRead,int[] headWidthArr
,ArrayList<ItemCell> itemCells,int rowNum
,ListView listView,KeyBoard keyBoard,CallBackInterface callBack){
this.context = context;
this.isRead = isRead;
this.headWidthArr = headWidthArr;
this.setOrientation(LinearLayout.VERTICAL);
this.rowNum = rowNum;
this.listView = listView;
this.keyBoard = keyBoard;
this.callBack = callBack;
this.type = type;
this.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,45));
this.addCell(itemCells);
}
public void refreshData(ArrayList<ItemCell> itemCells,int rowNum){
this.rowNum = rowNum;
this.refreshCells(itemCells);
}
private void refreshCells(ArrayList<ItemCell> itemCells){
for(int i=0;i<itemCells.size();i++){
ItemCell itemCell = itemCells.get(i);
if(itemCell.getCellType()==ItemCellValueType.VALUE_NONE){
TextView view = (TextView)viewList.get(i);
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_NUMBER){
EditText view= (EditText)viewList.get(i);
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
this.setOnKeyBorad(view, itemCell.getCellInRow());
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_STRING){
EditText view= (EditText)viewList.get(i);
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
}
}
}
private int getCellWidth(int cellStart,int cellEnd){
int width = 0;
for(int i=cellStart;i<cellEnd;i++){
width = this.headWidthArr[i] + width;
}
return width;
}
private void addCell(ArrayList<ItemCell> itemCells){
LinearLayout secondLayout = new LinearLayout(context);
secondLayout.setOrientation(LinearLayout.HORIZONTAL);
secondLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
this.addView(secondLayout);
int cellIndex = 0;
for(int i=0;i<itemCells.size();i++){
ItemCell itemCell = itemCells.get(i);
int endIndex = cellIndex+itemCell.getCellSpan();
int width = getCellWidth(cellIndex,endIndex);
cellIndex = endIndex;
if(itemCell.getCellType()==ItemCellValueType.VALUE_NONE){
TextView view = (TextView)getReadView();
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
view.setWidth(width);
secondLayout.addView(view);
viewList.add(view);
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_NUMBER){
EditText view= (EditText)getInputView();
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
view.setWidth(width);
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
this.setOnKeyBorad(view, itemCell.getCellInRow());
secondLayout.addView(view);
viewList.add(view);
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_STRING){
EditText view= (EditText)getInputView();
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
view.setWidth(width);
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
secondLayout.addView(view);
viewList.add(view);
}
if(i!=itemCells.size()-1){
LinearLayout v_line = (LinearLayout)getVerticalLine();
v_line.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
secondLayout.addView(v_line);
}
}
}
private View getVerticalLine(){
return LayoutInflater.from(context).inflate(R.layout.atom_line_v_view, null);
}
private View getReadView(){
return (View)LayoutInflater.from(context).inflate(R.layout.atom_text_view, null);
}
private View getInputView(){
return (View)LayoutInflater.from(context).inflate(R.layout.atom_edttxt_view, null);
}
private void setOnKeyBorad(EditText edtText1,int index){
if(!this.isRead){
onListenText(edtText1,this.listView,index);
}
}
private void onListenText(EditText edtText,ListView listView,int index){
final ListView lsv = listView;
final int idx = index;
edtText.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View arg0, boolean arg1) {
if(arg1){
int[] y = getYPos(lsv,idx);
keyBoard.show((EditText)arg0,y[0],y[1]);
}
}
});
}
private int[] getYPos(ListView listview,int index){
int[] yPosArr = new int[2];
Rect r = new Rect();
listview.getChildAt(0).getGlobalVisibleRect(r);
int first = listview.getFirstVisiblePosition();
yPosArr[1] = (index-first+1)*r.height()+listview.getTop();
yPosArr[0] = (index-first)*r.height()+listview.getTop();
return yPosArr;
}
private void setEditView(EditText edtText1,final String key){
if(this.isRead){
edtText1.setEnabled(false);
}else{
edtText1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
String[] arr = new String[3];
arr[0] = rowNum+"";
arr[1] = key;
arr[2] = arg0.toString();
callBack.exectueMethod(arr);
// ItemCell itemCell = (ItemCell)dataMap.get(key);
// itemCell.setCellValue(arg0.toString());
// itemCell.setIsChange(true);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
});
}
}
public String getType(){
return this.type;
}
}
public class ItemCell {
private String cellValue = "";
private int cellSpan = 1;
private String cellKey = "";
private int cellInRow = 0;
private long cellType = ItemCellValueType.VALUE_NONE;
private int colNum = 0;
private int rowType = 0;
private int cellId = -1;
private boolean isValueFromTable = false;
private boolean isChange = false;
public ItemCell(String cellValue,String cellKey,long cellType,int cellInRow,int cellSpan){
this.cellValue = cellValue;
this.cellType = cellType;
this.cellSpan = cellSpan;
this.cellKey = cellKey;
this.cellInRow = cellInRow;
}
public ItemCell(String cellValue,String cellKey,long cellType,int cellInRow){
this(cellValue,cellKey,cellType,cellInRow,1);
}
public void setColNum(int colNum){
this.colNum = colNum;
}
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 long getCellType(){
return cellType;
}
public int getCellSpan(){
return cellSpan;
}
public String getCellKey(){
return cellKey;
}
public int getCellInRow(){
return cellInRow;
}
public void setIsChange(boolean isChange){
this.isChange = isChange;
}
public boolean getIsChange(){
return this.isChange;
}
public int getCellId() {
return cellId;
}
public void setCellId(int cellId) {
this.cellId = cellId;
}
public boolean isValueFromTable() {
return isValueFromTable;
}
public void setValueFromTable(boolean isValueFromTable) {
this.isValueFromTable = isValueFromTable;
}
}
custome_list_item.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="vertical"
android:id="@+id/test_dajej"
android:background="#ffffff">
<srit.collection.widget.costomtable.ListItemCustom android:id="@+id/custome_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
以上是核心的文件內(nèi)容。有了列合并,行合并也不遠(yuǎn)了??梢栽谧远x的布局中多加個(gè)LinearLayout來(lái)實(shí)現(xiàn)行合并。

要實(shí)現(xiàn)的效果有幾方面
1、列不固定:可以根據(jù)數(shù)據(jù)源的不同生成不同的列數(shù)
2、表格內(nèi)容可以根據(jù)數(shù)據(jù)源的定義合并列
3、要填寫(xiě)的單元格可以選擇自定義鍵盤(pán)還是系統(tǒng)鍵盤(pán)
奔著這三點(diǎn),做了個(gè)簡(jiǎn)單的實(shí)現(xiàn),把源碼貼一下(因?yàn)樵擖c(diǎn)是主界面中的一部分,不便于放整個(gè)Demo)
自定義適配器,CallBackInterface是自定義的回調(diào)接口,這里定義回調(diào)是因?yàn)閿?shù)據(jù)輸入時(shí)需要及時(shí)保存
復(fù)制代碼 代碼如下:
public class SiteDetailViewAdapter extends BaseAdapter implements CallBackInterface{
private Context context;
private LayoutInflater inflater;
private ArrayList<HashMap<String,Object>> lists;
private KeyBoard keyBoard = null;//自定義鍵盤(pán)
private ListView listView = null;
private boolean isReadOnly = false;//是否是瀏覽狀態(tài)
private String[] arrCellType = null;
private int[] arrHeadWidth = null;//每列寬度
public SiteDetailViewAdapter(Context context, ArrayList<HashMap<String,Object>> lists
,KeyBoard keyBoard,ListView listView,boolean isReadOnly
,int[] arrHeadWidth) {
super();
this.context = context;
this.lists = lists;
inflater = LayoutInflater.from(context);
this.keyBoard = keyBoard;
this.listView = listView;
this.isReadOnly = isReadOnly;
this.arrHeadWidth = arrHeadWidth;
this.listView.setAdapter(this);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return lists.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int index, View view, ViewGroup arg2) {
HashMap map = lists.get(index);
String type = (String)map.get("rowtype");
ArrayList<ItemCell> itemCells = new ArrayList();
//String cellValue,String cellKey,long cellType,int cellInRow,int cellSpan
ItemCell itemCellXuHao = new ItemCell((index+1)+"","-1",1,-1,1);
itemCells.add(itemCellXuHao);
for(int i=0;i<map.size()-1;i++){
ItemCell itemCell = (ItemCell)map.get(i+"");
itemCells.add(itemCell);
}
//性能優(yōu)化后需要放開(kāi)注釋danielinbiti
if(view == null||view!=null&&!((ListItemCustom)view.getTag()).getType().equals(type)){
view = inflater.inflate(R.layout.customel_list_item, null);
ListItemCustom itemCustom = (ListItemCustom)view.findViewById(R.id.custome_item);
itemCustom.buildItem(type, context, isReadOnly,arrHeadWidth,itemCells,index
,this.listView,this.keyBoard,this);
view.setTag(itemCustom);
}else{
ListItemCustom itemCustom = (ListItemCustom)view.getTag();
itemCustom.refreshData(itemCells,index);
}
if(index%2 == 0){
view.setBackgroundColor(Color.argb(250 , 255 , 255 , 255 ));
}else{
view.setBackgroundColor(Color.argb(250 , 224 , 243 , 250 ));
}
return view;
}
@Override
public boolean exectueMethod(Object params) {
String[] arr = (String[])params;
HashMap map = lists.get(Integer.parseInt(arr[0]));
ItemCell itemCell = (ItemCell)map.get(arr[1]);
itemCell.setCellValue(arr[2]);
itemCell.setIsChange(true);
return false;
}
ListView每行的布局,內(nèi)部代碼是有冗余的,因?yàn)槭荄emo,所以先以效果未準(zhǔn),未進(jìn)行代碼重構(gòu),注意不能往ListItemCustom中傳入每行的Map來(lái)進(jìn)行值得獲取或者輸入更新等操作,因?yàn)镸ap是按地址方式,再結(jié)合ListView的繪制方式,最終的map不是你想象的map。
復(fù)制代碼 代碼如下:
public class ListItemCustom extends LinearLayout{
public ListItemCustom(Context context){
super(context);
}
public ListItemCustom(Context context, AttributeSet attrs) {
super(context, attrs);
}
private String type = "-1";
private Context context = null;
private boolean isRead = false;
private int[] headWidthArr = null;
private ListView listView = null;
private KeyBoard keyBoard = null;
private int orderNum = -1;
private ArrayList<View> viewList = new ArrayList();
private int rowNum = -1;
private CallBackInterface callBack = null;
public void buildItem(String type,Context context,boolean isRead,int[] headWidthArr
,ArrayList<ItemCell> itemCells,int rowNum
,ListView listView,KeyBoard keyBoard,CallBackInterface callBack){
this.context = context;
this.isRead = isRead;
this.headWidthArr = headWidthArr;
this.setOrientation(LinearLayout.VERTICAL);
this.rowNum = rowNum;
this.listView = listView;
this.keyBoard = keyBoard;
this.callBack = callBack;
this.type = type;
this.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,45));
this.addCell(itemCells);
}
public void refreshData(ArrayList<ItemCell> itemCells,int rowNum){
this.rowNum = rowNum;
this.refreshCells(itemCells);
}
private void refreshCells(ArrayList<ItemCell> itemCells){
for(int i=0;i<itemCells.size();i++){
ItemCell itemCell = itemCells.get(i);
if(itemCell.getCellType()==ItemCellValueType.VALUE_NONE){
TextView view = (TextView)viewList.get(i);
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_NUMBER){
EditText view= (EditText)viewList.get(i);
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
this.setOnKeyBorad(view, itemCell.getCellInRow());
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_STRING){
EditText view= (EditText)viewList.get(i);
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
}
}
}
private int getCellWidth(int cellStart,int cellEnd){
int width = 0;
for(int i=cellStart;i<cellEnd;i++){
width = this.headWidthArr[i] + width;
}
return width;
}
private void addCell(ArrayList<ItemCell> itemCells){
LinearLayout secondLayout = new LinearLayout(context);
secondLayout.setOrientation(LinearLayout.HORIZONTAL);
secondLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
this.addView(secondLayout);
int cellIndex = 0;
for(int i=0;i<itemCells.size();i++){
ItemCell itemCell = itemCells.get(i);
int endIndex = cellIndex+itemCell.getCellSpan();
int width = getCellWidth(cellIndex,endIndex);
cellIndex = endIndex;
if(itemCell.getCellType()==ItemCellValueType.VALUE_NONE){
TextView view = (TextView)getReadView();
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
view.setWidth(width);
secondLayout.addView(view);
viewList.add(view);
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_NUMBER){
EditText view= (EditText)getInputView();
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
view.setWidth(width);
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
this.setOnKeyBorad(view, itemCell.getCellInRow());
secondLayout.addView(view);
viewList.add(view);
}else if(itemCell.getCellType()==ItemCellValueType.VALUE_STRING){
EditText view= (EditText)getInputView();
view.setId(itemCell.getCellId());
view.setText(itemCell.getCellValue());
view.setWidth(width);
//view.setText(itemCell.getCellId()+"");
//view.setTag(itemCell.getCellKey()+"");
this.setEditView(view,itemCell.getCellKey());
secondLayout.addView(view);
viewList.add(view);
}
if(i!=itemCells.size()-1){
LinearLayout v_line = (LinearLayout)getVerticalLine();
v_line.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
secondLayout.addView(v_line);
}
}
}
private View getVerticalLine(){
return LayoutInflater.from(context).inflate(R.layout.atom_line_v_view, null);
}
private View getReadView(){
return (View)LayoutInflater.from(context).inflate(R.layout.atom_text_view, null);
}
private View getInputView(){
return (View)LayoutInflater.from(context).inflate(R.layout.atom_edttxt_view, null);
}
private void setOnKeyBorad(EditText edtText1,int index){
if(!this.isRead){
onListenText(edtText1,this.listView,index);
}
}
private void onListenText(EditText edtText,ListView listView,int index){
final ListView lsv = listView;
final int idx = index;
edtText.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View arg0, boolean arg1) {
if(arg1){
int[] y = getYPos(lsv,idx);
keyBoard.show((EditText)arg0,y[0],y[1]);
}
}
});
}
private int[] getYPos(ListView listview,int index){
int[] yPosArr = new int[2];
Rect r = new Rect();
listview.getChildAt(0).getGlobalVisibleRect(r);
int first = listview.getFirstVisiblePosition();
yPosArr[1] = (index-first+1)*r.height()+listview.getTop();
yPosArr[0] = (index-first)*r.height()+listview.getTop();
return yPosArr;
}
private void setEditView(EditText edtText1,final String key){
if(this.isRead){
edtText1.setEnabled(false);
}else{
edtText1.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
String[] arr = new String[3];
arr[0] = rowNum+"";
arr[1] = key;
arr[2] = arg0.toString();
callBack.exectueMethod(arr);
// ItemCell itemCell = (ItemCell)dataMap.get(key);
// itemCell.setCellValue(arg0.toString());
// itemCell.setIsChange(true);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
});
}
}
public String getType(){
return this.type;
}
}
復(fù)制代碼 代碼如下:
public class ItemCell {
private String cellValue = "";
private int cellSpan = 1;
private String cellKey = "";
private int cellInRow = 0;
private long cellType = ItemCellValueType.VALUE_NONE;
private int colNum = 0;
private int rowType = 0;
private int cellId = -1;
private boolean isValueFromTable = false;
private boolean isChange = false;
public ItemCell(String cellValue,String cellKey,long cellType,int cellInRow,int cellSpan){
this.cellValue = cellValue;
this.cellType = cellType;
this.cellSpan = cellSpan;
this.cellKey = cellKey;
this.cellInRow = cellInRow;
}
public ItemCell(String cellValue,String cellKey,long cellType,int cellInRow){
this(cellValue,cellKey,cellType,cellInRow,1);
}
public void setColNum(int colNum){
this.colNum = colNum;
}
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 long getCellType(){
return cellType;
}
public int getCellSpan(){
return cellSpan;
}
public String getCellKey(){
return cellKey;
}
public int getCellInRow(){
return cellInRow;
}
public void setIsChange(boolean isChange){
this.isChange = isChange;
}
public boolean getIsChange(){
return this.isChange;
}
public int getCellId() {
return cellId;
}
public void setCellId(int cellId) {
this.cellId = cellId;
}
public boolean isValueFromTable() {
return isValueFromTable;
}
public void setValueFromTable(boolean isValueFromTable) {
this.isValueFromTable = isValueFromTable;
}
}
custome_list_item.xml文件
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="vertical"
android:id="@+id/test_dajej"
android:background="#ffffff">
<srit.collection.widget.costomtable.ListItemCustom android:id="@+id/custome_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
以上是核心的文件內(nèi)容。有了列合并,行合并也不遠(yuǎn)了??梢栽谧远x的布局中多加個(gè)LinearLayout來(lái)實(shí)現(xiàn)行合并。
您可能感興趣的文章:
- Android使用GridView實(shí)現(xiàn)表格分割線效果
- Android自定義View實(shí)現(xiàn)課程表表格
- Android自定義View實(shí)現(xiàn)仿GitHub的提交活躍表格
- Android listView 繪制表格實(shí)例詳解
- Android自定義DataGridView數(shù)據(jù)表格控件
- Android應(yīng)用中通過(guò)Layout_weight屬性用ListView實(shí)現(xiàn)表格
- Android中使用ListView實(shí)現(xiàn)漂亮的表格效果
- Android提高之ListView實(shí)現(xiàn)自適應(yīng)表格的方法
- android表格效果之ListView隔行變色實(shí)現(xiàn)代碼
- Android自定義view繪制表格的方法
相關(guān)文章
Android 集成Google Cast 異常問(wèn)題解析
這篇文章主要為大家介紹了Android 集成Google Cast 異常問(wèn)題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02Android編程之SharedPreferences文件存儲(chǔ)操作實(shí)例分析
這篇文章主要介紹了Android編程之SharedPreferences文件存儲(chǔ)操作方法,實(shí)例分析了SharedPreferences文件操作的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04Android實(shí)戰(zhàn)打飛機(jī)游戲之子彈生成與碰撞以及爆炸效果(5)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)戰(zhàn)打飛機(jī)游戲之子彈生成與碰撞以及爆炸效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07Android編程程序?qū)崿F(xiàn)一鍵鎖屏的方法講解
今天小編就為大家分享一篇關(guān)于Android編程程序?qū)崿F(xiàn)一鍵鎖屏的方法講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03務(wù)必掌握的Android十六進(jìn)制狀態(tài)管理最佳實(shí)踐
這篇文章主要為大家介紹了務(wù)必掌握的Android十六進(jìn)制狀態(tài)管理最佳實(shí)踐,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09