2

I am sure there is an easy solution to this one but I figured I would check with all the folks here first.

I am working on a database creation and management application for android where the user creates and manages data along the line of what PHPMyAdmin does for regular computers.

I have the section where the user creates a database and can insert tables with the appropriate styled data into the system.

The next priority is selecting which DB to enter and modify its contents. Is there a way to display the available databases, along with its table contents, in the form of a list-view for the user to enter and edit the desired data??

I know that this is a rather dull question, but this is basically the last piece of the puzzle for me to fit into this app before it is operational in a raw format. If you need any further information, or any code to examine, I will be happy to provide.

Thanks again for everyone's assistance.

2 Answers 2

0

Here's a good tutorial on SQLite databases and displaying contents in a ListView: http://www.vogella.com/articles/AndroidSQLite/article.html#databasetutorial

It doesn't go over editing that much, but it's easy to see where he puts the values into the database.

thenewboston on YouTube is a good resource for Android tutorials and he goes over SQLite databases: http://www.youtube.com/watch?v=gEg9OdufXmM

It's pretty comprehensive and slow if you already kinda know what you're doing so here is where he goes over inserting data/editing the database if you just wanna jump to that: http://www.youtube.com/watch?v=S3Z4e7KgNdU

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the suggestions. I have indeed watched thenewboston on sqlite and have a fair understanding of how to make the commands and user-updates. As I mentioned, what i am looking for is how to view all available databases in a listview.
That would probably go along the lines of exploring the folder where you made all the databases and getting their file names and putting them into a listview similar to what the tutorials are doing with contents of the database, then opening the db that the user selects.
So is that something along the line of an inputStream jumping into the app's data file, collecting the names of the DBs and parsing them into a list?
-1

I know this below can be optimized but for now just create such a method to do it automatically. The method...

  1. Creates an empty database of a random name for a second,
  2. Saves the new database's location - getDatabasePath,
  3. Quikly deletes the empty database,
  4. Removes filename form the saved path to get the directory path olny,
  5. List all files in the database path excluding '-journal' files.

And it goes like this:

ArrayList<String> arr_list_of_db_files = getDBFILES();

pivate ArrayList<String> getDBFILES() 
  {
   ArrayList<String> arr = new ArrayList<String>;
   String db_path, rand_name, str_tmp;

   //ad.1-2. random file name for db   
   rand_name = new Random().nextInt((4000000-2000+1)+2000).toString()+".db";
   db_path = openOrCreateDatabase(rand_name, MODE_PRIVATE, null).getPath();

   //ad.3.
   deleteDatabase(rand_name);

   //ad.4.
   db_path = db_path.replace("/" + rand_name, "");

   //ad.5.
   File [] files = new File(db_path).listFiles();
   if (files == null) { return null; }

   //so now we get the filenames one by one
   for (int i = 0; i < files.length; i++)
       { 
          str_tmp = files[i].getName();
          if (!str_tmp.endsWith("-journal"))
             {  arr.add(str_tmp); }
       }
   return arr;
  }

Btw, I cant test the code, but I hope it is fine and some of you find it useful.

Edited: I have optimized the above code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.