Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:44:30+00:00 2026-05-28T04:44:30+00:00

As it stands right now, I have a TableLayout that I am populating based

  • 0

As it stands right now, I have a TableLayout that I am populating based on certain columns and every row from a .db file. The table is populated based upon a single .db file which I will call x from now on. Every time the activity is recreated, my populate method (what populates the table) checks to see what is in x.db. Every row in the table has the same 3 columns, but if you long press a row then you can see every detail of this row (the details calculate one of the column displays and the calculation is different for each row).

From here the user has the option to calculate a grand total, save the current .db file, load a different .db file, or clear the .db file and start over. Here is how I am handling the saving and loading, which is what my question is about (I had to change some of the names of variables to be able to post)

case R.id.save:
            SAVE_DIALOG = R.id.save;

            AlertDialog.Builder save_alert = new AlertDialog.Builder(this,3);

            edit = new EditText(this);
            edit.setSingleLine();
            save_alert.setTitle("Please enter a name to save as");
            save_alert.setView(edit);               
            save_alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {  
                    if(edit.getText().toString().trim().isEmpty()){
                        Toast toast = Toast.makeText(getApplicationContext(), "Name must not be blank", Toast.LENGTH_LONG);
                        toast.show();
                        return;
                    }
                    else {
                    File makeDirectory = new File("data/data/com.project.project/databases/stored_x");
                    if(!makeDirectory.isDirectory())
                        makeDirectory.mkdir();
                    FileChannel fromChannel = null;
                    FileChannel toChannel = null;
                    try {
                        File input = new File("data/data/com.project.project/databases/x.db");
                        //File output = new File("data/data/com.project.project/databases/stored_x/"+ edit.getText() +".db");
                        File output = new File("data/data/com.project.project/databases/stored_x/"+ edit.getText());
                        FileInputStream in = new FileInputStream(input);
                        FileOutputStream out = new FileOutputStream(output);
                        fromChannel = in.getChannel();
                        toChannel = out.getChannel();
                        fromChannel.transferTo(0, fromChannel.size(), toChannel);
                    } 
                    catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }   
                    finally {
                         try {
                            fromChannel.close();
                            } 
                         catch (IOException e) {
                            e.printStackTrace();
                            }
                         try {
                            toChannel.close();
                            }
                         catch (IOException e) {
                            e.printStackTrace();
                            }
                        }
                    }
                }
            });
            save_alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                  }
                 });    
            AlertDialog saveAlert = save_alert.create();
            saveAlert.setCanceledOnTouchOutside(true);
            saveAlert.show();               
            break;

After the user presses the save button, an alert dialog appears asking the user for a name to save the file as. After the user input a name and presses ok, the file is copied and stored in a folder that I make in “data/data/com.project.project/databases/stored_x/” So I am just making a copy of the .db file and putting it somewhere else.

In order to load I do something similar to save, except I chose the file view a listview and replace the current x.db with this file, now calling it x.db.

Everything works fine, and will work fine for the end users, but I am just curious if this is the way it is supposed to be done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:44:31+00:00Added an answer on May 28, 2026 at 4:44 am

    Ok so your query to get all items of a specify type would be something like this …

    SELECT * FROM table_name WHERE type='some_type'
    

    To insert a data into the database would be like this …

    INSERT INTO table_name ('name', 'description', 'type') VALUES ('Foo', 'Bar', 'some_type')
    

    You can get a list of of different types by running this query

    SELECT DISTINCT type FROM table_name
    

    Android has build in classes that make query a database alot eaier. The SQLiteDatabase makes quering databases so much easier. I prefer to use the rawQuery() method but you can use the wrapper methods if you like. Here is an example for using the rawQuery method.

    db.rawQuery("SELECT * FROM table_name WHERE type=?", new String[] {"some_type"});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a class/table called Images that, as it stands right
I have a problem that involves biology area. Right now I have 4 VERY
As it stands right now, I have a literal control on my page. In
I have been optimizing my website but the one problem that stands in my
I have two development teams, that come from different groups. Group A develops against
Suppose I have a program running that periodically adds information to a .CSV file.
I have a website im working on and right now it has a gradient
As it stands now, I'm a Java and C# developer. The more and more
What is a .snk file for? I know it stands for Strongly Named Key
Is there any substantial difference between those two terms?. I understand that JDK stands

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.