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.

4

2 回答 2

0

这是一个关于 SQLite 数据库和显示内容的好教程ListViewhttp ://www.vogella.com/articles/AndroidSQLite/article.html#databasetutorial

它并没有过多地编辑,但很容易看出他将值放入数据库的哪个位置。

YouTube 上的 thenewboston 是一个很好的 Android 教程资源,他浏览了SQLite数据库: http ://www.youtube.com/watch?v=gEg9OdufXmM

如果您已经有点知道自己在做什么,那么它非常全面且缓慢,如果您只想跳到这里,他会在这里插入数据/编辑数据库: http ://www.youtube.com/watch?v= S3Z4e7KgNdU

于 2013-04-22T01:53:26.250 回答
-1

我知道下面可以优化,但现在只需创建这样的方法来自动完成。方法...

  1. 在一秒钟内创建一个随机名称的空数据库,
  2. 保存新数据库的位置 - getDatabasePath
  3. 快速删除空数据库,
  4. 从保存的路径中删除文件名以获取目录路径 olny,
  5. 列出数据库路径中的所有文件,不包括“-journal”文件。

它是这样的:

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;
  }

顺便说一句,我无法测试代码,但我希望它很好,你们中的一些人会觉得它有用。

编辑:我已经优化了上面的代码。

于 2013-10-27T02:49:12.653 回答