How to view my Android app created database, via my android app?
Posted
by
suufang
on Stack Overflow
See other posts from Stack Overflow
or by suufang
Published on 2012-11-04T06:30:21Z
Indexed on
2012/11/04
11:01 UTC
Read the original article
Hit count: 182
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,
- To collect users CB location.
- To collect a custom name from user of that location.
- To store these values in a database.
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,
Now,
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.
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.
Help required.
Thank you.
© Stack Overflow or respective owner