Wednesday, 15 February 2012

codenameone - how can I add a row dynamically -


I want to add the dynamic of the rows without disturbing other data in the table (data is [] DataForTable .Data does not want to continue with the data). To do this, I did not find any method from TableModel or Table. What is the way to get it without object [] [] data-photostable or any other way?

I have another situation at any time, I need an extra row in the table that is empty. And when you add value to this row, another empty line will be created dynamically.

Update: I have re-evaluated this answer and some bugs And ideological problems. We have decided to add options to add / remove rows from the table. You can use the .ADRow ("Col1", "Col2", "Col3") (but the defaultTableModel table); Just make sure the number of columns is the exact match for the counting of the table columns.

Below is the original answer:

The default table model is not unstable, which is probably a mistake on our part, something like this should probably work (not tested ):

  Public class MyTableModel applicable tablemodel {Private ArrayList & lt; Object []) data; Private string [] columnNames; Private Event Dispatcher Dispatcher = New Event Dispatch (); Private Boolean Editable; Public MyTableModel (string [] columnname, object [] [] data) {This (column name, data, wrong); } Public MyTableModel (string [] columnname, object [] [] data, boolean editable) {this.data = new ArrayList & lt; Object [] & gt; (); (Object [] o: for data) {this.data.add (o); } This.columnNames = columnNames; This.editable = Editable; } / ** * @Herch Doc * / Public IntroOcount () {Return Data. Long; } / ** * @Herch Doc * / Public Intimate Cocktail Call () {Return column name. Long; } / ** * @Herch Doc * / Public String getColumnName (int i) {return column names [i]; } / ** * @Herch Doc * / Public Boolean is cell adetse (int row, at column) {edit editable; } / ** * @Herch Dock * / Public object getValueAt (int row, at column) {try {return data.get (line) [column]; } Hold (ArrayIndexOutOfBoundsException err) {// is not the best position, but the resource editor is very useful for //err.printStackTrace (); Return ""; }} / ** * @Herch Dock * / Public Zero Set Value (int row, at column, object o) {data.get (row) [column] = o; Dispatcher.fireDataChangeEvent (column, row); } / ** * @Harlet Doc * / Public Zero addDataChangeListener (DataChangedListener) {dispatcher.addListener (D); } / ** * @HerHit Doc * / Public Zero Extract Data Change Listener (Data Changed Listener D) {dispatcher.removeListener (d); } Public Zero addRow (object [] line) {data.add (line); Dispatcher.fireDataChangeEvent (-1, line); }}  

No comments:

Post a Comment