Hello. I’m sitting on my head, I can’t find examples to clarify such a moment for myself. Suppose we do not have any database. The person in the application enters the database name, rows, columns, contents. DB is created. Then the person forgot to enter a couple more columns or rows and added again to the same table. Each time you turn on the application already knows which tables we have.

I am about to present the implementation as follows: A simple table is created in one database:
--- b1 b2 b3
a1
a2
a3
Further, the second table shows the names
a1
a2
a3
Third
b1
b2
b3
Perhaps the third and fourth for their needs.

So, in all examples, tables with the necessary columns are created in advance and then data on rows is very simply added. As in principle, it is done in one of my applications, where each row of my corresponds to an array of several data that correspond to columns.

So the question itself is, how can you make the columns grow in a similar way? Very interested in this issue ...

In general, I understand that there is Excel and, if desired, you can turn the whole thing in it, but unfortunately I do not have such an opportunity.

  • Do not understand what you want to do? Dynamically build up new columns? What for? Describe your task in one - two sentences. - Romag
  • I have a little overclocked, so to speak. Screwed the dynamic creation of tables in my database with names attached to them. In two sentences it is difficult ... I'll try. In general, there is a table with rows and columns, the user adds the name of the rows and columns, and then the table is filled with numbers. At the moment, I'm interested in adding new columns, in which the first row will be responsible for the title and already load these names into the listview. In general, it already seems to me that there is a simpler solution. Apparently I love to conquer Everest. - Antonem
  • If it is even shorter, then there will be some operations for working with matrices, this is still, so to speak, the beginning ... - Antonem
  • Or how to make it so that everything is read from one line until it reaches the end and each column of this line is written separately in the list view. - Antonem

1 answer 1

Everything that I wrote at the very beginning at the moment has been implemented, until it is very beautiful, I will finish the beauty later, and thereby reduce the code. And now to the main question, which I will answer myself:

So the question itself is, how can you make the columns grow in a similar way?

Without haste, I got to this piece of code. To work with the database I have created a separate Java Class DB in it I have written:

public void add() { String SQL = "ALTER TABLE " + TABLE + " ADD COLUMN " + NAME +" TEXT;"; DB.execSQL(SQL); } 

From the main class Main:

 DB.add(); 

And it works.
Of course in the program I have a little more complicated, namely:

 public void add(Integer a, Integer b) { TABLE = "A"+a; NAME = "B"+b; String SQL = "ALTER TABLE " + TABLE + " ADD COLUMN " + NAME +" TEXT;"; DB.execSQL(SQL); } 

From the main class Main:

 DB.add(a, b); 

As a result, I bring in a number known in advance to me in the name of the tables, we get A0, A1, etc. and depending on the desired table I am already adding columns B0, B1, etc. If of course there is something simpler than this method, then I will consider with pleasure.

Thank you all for your help!