/** * Fill the client Data table from an Android Cursor Database * * @param pCursor */ public void fillFromCursor(Cursor pCursor) { _mCursor = pCursor; _mCursorSize = pCursor.getCount(); _mListOfRows.clear(); _mListOfRows.ensureCapacity(_mCursorSize); String[] lCursorColumnsNames = pCursor.getColumnNames(); int lNbrColumnsCDT = getColumnsCount(); int lNbrColumnsCursor = lCursorColumnsNames.length; if (lNbrColumnsCDT == 0) { for (int i = 0; i < lNbrColumnsCursor; i++) { _mListOfColumns.add(new TColumn(lCursorColumnsNames[i], ValueType.TEXT)); } } if (_mCursorSize > 0) { pCursor.moveToFirst(); _mPosition = 0; while (!pCursor.isAfterLast()) { TRow lRow = new TRow(); if (lNbrColumnsCDT > 0) { for (int i = 0; i < lNbrColumnsCDT; i++) { boolean lIsColumnFound = false; TColumn lColumn = _mListOfColumns.get(i); for (int j = 0; j < lNbrColumnsCursor; j++) { if (lColumn != null && lColumn.getName().equals(lCursorColumnsNames[j])) { lRow.addCell(_mContext, pCursor.getString(j), lColumn.getValueType(), _mCDTStatus); lIsColumnFound = true; break; } } if (!lIsColumnFound) lRow.addCell(_mContext, "", lColumn.getValueType(), _mCDTStatus); } } else { for (int i = 0; i < lNbrColumnsCursor; i++) { String lColumnName = lCursorColumnsNames[i]; if (lColumnName != null && !lColumnName.equals("")) lRow.addCell(_mContext, pCursor.getString(i), ValueType.TEXT, _mCDTStatus); } } _mListOfRows.add(lRow); pCursor.moveToNext(); } } Log.i("fillFromCursor", " Count :" + _mCursorSize); }
/** * Add row from values with differents type : boolean, String etc... * * @param values */ public void addRowFromValues(Object... values) { Iterator<TColumn> columnIt = _mListOfColumns.listIterator(); TRow lRow = new TRow(); for (int i = 0; i < values.length && columnIt.hasNext(); i++) { TColumn lCol = columnIt.next(); if (_mSqliteDataBase == null) lRow.addCell(_mContext, values[i], lCol.getValueType(), _mCDTStatus); else lRow.addCell(_mContext, values[i], lCol.getValueType(), _mCDTStatus); } addRow(lRow); }