I have three layout in this app. I would like to save the data that I have in the first layout to a database. And the second layout is supposed to show the list of files that I have saved in the database. I got a list view in the second layout, how do I make it so that the files can just add in to the database and show it in the list view in layout 2. Can anyone help me with this?
I'm sorry. What I am trying to do now is to create a database or something like an excel table or more if there's a choice for my data collection app. The First layout from the picture that I've show was supposed to be a key in entry to enable the numbers to be stored in the database and the Second layout is a list view that will show the list of recorded info/files from the database. Can you help me with that please? I am clueless on how to link it all together
Your project will not work, because your sql statements are complete wrong:
B4X:
Sub CreateTables
SQL1.ExecNonQuery( "col1 Integer, col2 Integer, col3 Integer, col4 Integer, col5 Integer, col6 Integer") 'no Create Table here
End Sub
Sub FillSimpleData
SQL1.ExecNonQuery("INSERT INTO table1 VALUES('Date', 'Time', 'Frond', 'Bunch', 'Latitude', 'Longitude')") 'your colums are type integer, you can not insert strings like here...
End Sub
The first statement the key words like "Create Table" are missing, in the second you try to insert Strings into integer fields and so on. If you want to build solid apps you should read a bit about databases and something about SQL. Start with https://www.b4x.com/android/forum/threads/sql-tutorial.6736/
Okay I have tried another method instead of using SQL. Unfortunately when I press the save button in the first layout it just shuts off. Does anyone know what is wrong in the coding? I'll attach the file below.
yes, you are trying to load a non existing file. Use the debugger and logs and it will give you the information you'll need...
Error occurred on line: 74 (Main)
java.io.FileNotFoundException: /storage/emulated/0/data.txt: open failed: ENOENT (No such file or directory)
Sub Save_click
input=File.readstring(File.DirRootExternal,"data.txt") 'there is no need to open the file, because you don't make nothing with data
data=Regex.split(input,",") 'so you can set this to comment or use if file.exists(File.DirRootExternal,"data.txt")) then...
output=EditText1.text &","& EditText2.text &","& Lat.text &","& Lon.text
File.writestring(File.DirRootExternal,"data.txt",output)
ToastMessageShow("Saved",True)
End Sub