如何查看我创建的数据库Android应用程序,通过我的Andr​​oid应用程序? [英] How to view my Android app created database, via my android app?

查看:109
本文介绍了如何查看我创建的数据库Android应用程序,通过我的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个收集用户的位置(小区广播的位置code)和保存该位置与用户选择的名称的应用程序,
例如说我的CB位置code为546034,现在我的应用程序可以让我来存储位置code与我选择的名称说'家'。

I'm creating an application that collects users location (Cell broadcast location code) and saves that location with a name of users option, for example say my CB location code is 546034, now my app allows me to store that location code with a name of my choice say 'Home'.

所以,基本上我的应用程序有以下模块,

So, essentially my app has that following modules,


  1. 要收集用户位置的CB

  2. 要在该位置收集用户自定义名称。

  3. 要在数据库中存储这些值。

我已经成功地做​​到了上述所有模块。

I've succeeded in doing all the above modules.

我有我的第三个模块的子模块,对用户提供一个选项,显示和删除数据库中的值,屏幕截图如下所示,

I have a sub-module for my third module which has an option for user, of showing and deleting the database values, the screen shot looks as follows,

现在,

用户应该能够查看,当他选择的选项查看我的位置数据库'我已经学会了如何查询我的数据库的价值观和我卡与创建一个列表视图,并提供删除选项删除条目。

Users should be able to view and delete entries when he chooses the option 'View my database of locations' I've learned how to query my database values and I'm stuck with creating a list view and providing the delete option.

我的code用于获取数据库值和查询值的情况如下,

My code for getting the database values and querying values goes as follows,

submit.setOnClickListener(new View.OnClickListener() 
    {

        public void onClick(View arg0) {

            String locname = name.getText().toString();

            if(locname.length()==0)
            {
                Toast.makeText(getBaseContext(), "Please enter the location     name, for example 'Home'.", Toast.LENGTH_LONG).show();
            }
            else
            {
                SQLiteDatabase cd = openOrCreateDatabase("mydata",    MODE_WORLD_READABLE, null);
                cd.execSQL("CREATE TABLE IF NOT EXISTS MLITable  (CblocationCode INT(10), CblocationName VARCHAR);");
                cd.execSQL("INSERT INTO MLITable VALUES ('"+str+ "','"+locname+ "');");
                cd.close();
                Toast.makeText(getBaseContext(), "value successfully entered.", Toast.LENGTH_LONG).show();
            }
        }
    });

    viewdb.setOnClickListener(new View.OnClickListener() 
    {

        public void onClick(View arg0) {
            // here comes the code for viewing the database and deleting

            SQLiteDatabase db = openOrCreateDatabase("mydata", MODE_WORLD_READABLE, null);
            Cursor c = db.rawQuery("SELECT * FROM MLITble", null);
            db.close();
        }
    });

我可以看到我读过表中的值,但我不能创建一个显示为这些值。

I can see that I've read the table values, but I'm not able to create a display for those values.

需要帮助。

感谢您。

推荐答案

您是从数据库中获取数据,但没有code来显示它们。您需要创建一个ListView什么来显示数据。

You are getting the data from the database but there is no code to display them. You need to create a ListView or something to display the data.

这里是如何做到这一点的教程:

here's a tutorial on how to do this:

http://tausiq.word$p$pss.com/2012/08/22/android-list-view-from-database-with-cursor-adapter/

这篇关于如何查看我创建的数据库Android应用程序,通过我的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆