0

I am planning to build an app that lets the user select a record from a particular database such as:

               name    favorite_color       favorite_team  
               sue        red                  Dal
               mike       blue                 Mia
               sam        purple               Bal

My problem is that most of the tutorials that I have come across only demonstrates examples using a table with one column. What if my pre-populated database more then on column? What if it had 100 columns? Does anyone know how this is done?????

1
  • unclear ur question...plz explain Commented Nov 1, 2011 at 4:47

2 Answers 2

1

Here's an example:

Step1:Declare SQLiteDatabase,Declare Databasehelper

Step2:Declare string or number which is to be used as key or get it as an intent(in this example 'rowid'

Step 3: In the OnCreate method add lines of code similar to following:

        String query="select * from my_table_name where _id="+rowid;
        Cursor myCursor = database.rawQuery(query,null);
        myCursor.moveToFirst();
        //This line implies i am getting data from column four of selected row
        String x=myCursor.getString(4);
        //This line implies i am getting data from column two of selected row
        String y=myCursor.getString(4);
        myCursor.close();

Note: a)Don't forget that your database size must not exceed 1.2mb

b)Also include a column with name _id which auto-increments in each table that you are using,you may use sqlite browser to do so

c)also create the following table in your database :

CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US')

Now insert a single row with the text 'en_US' in the "android_metadata" table

INSERT INTO "android_metadata" VALUES ('en_US')
Sign up to request clarification or add additional context in comments.

Comments

0

read this you will learn every thing you need to know. One other way to access db information is using an ORM like ormlite. I'm using it in various apps that i've developed, and it's simple to use.

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.