Check this out,
http://groups.google.com/group/android-developers/browse_thread/thread/aee4be30ed6c737b/268dcd8155a059b3?lnk=gst&q=autocomplete#268dcd8155a059b3

On 4 mar, 07:22, aljo <aljochim...@gmail.com> wrote:
> i'm kinda new to this android application and still a newbei to
> programming so hope someone could help me....
>
> i've created an SQLite database program.. but i don't know how to use
> theautocompletefunction to access my database... here's my code:
>
> --------------------------------------------------------------------------------------------------------------------------------------
>
> package database.dev5;
>
> import java.util.ArrayList;
>
> import android.app.ListActivity;
> import android.database.Cursor;
> import android.database.sqlite.SQLiteDatabase;
> import android.os.Bundle;
> import android.widget.ArrayAdapter;
> import android.widget.EditText;
>
> public class Database extends ListActivity {
>
>         private final String MY_DATABASE_NAME = "myCoolDB_2";
>         private final String MY_DATABASE_TABLE = "Users";
>
>         /** Called when the activity is first created. */
>         @Override
>         public void onCreate(Bundle icicle) {
>                 super.onCreate(icicle);
>
>                 EditText et = new EditText(this);
>                 et.setSelection(et.getText().length());
>                 /* Will hold the 'Output' we want to display at the end. */
>                 ArrayList<String> results = new ArrayList<String>();
>
>                 SQLiteDatabase myDB = null;
>                 try {
>
>                         //Create the Database (no Errors if it already exists)
>                         this.openOrCreateDatabase(MY_DATABASE_NAME, 
> MODE_PRIVATE, null);
>                         // Open the DB and remember it
>                         myDB = this.openOrCreateDatabase(MY_DATABASE_NAME, 
> MODE_PRIVATE,
> null);
>
>                         //this.deleteDatabase(MY_DATABASE_NAME);
>
>                         // Create a Table in the Database.
>                         myDB.execSQL("CREATE TABLE IF NOT EXISTS "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (English VARCHAR, 
> Japanese VARCHAR,"
>                                                         + " MASU_Form 
> VARCHAR, Definition VARCHAR);");
>
>                         //myDB.delete(MY_DATABASE_TABLE, null, null);
>
>                         // Add two DataSets to the Table.
>                         /*myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (English, 
> Japanese, MASU_Form, Definition)"
>                                                         + " VALUES ('yes', 
> 'hai', 'NA', 'noun');");
>                         myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (English, 
> Japanese, MASU_Form, Definition)"
>                                                         + " VALUES ('yes', 
> 'ee', 'NA', 'noun');");
>                         myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (English, 
> Japanese, MASU_Form, Definition)"
>                                                         + " VALUES ('call', 
> 'kakeru', 'kakemasu', 'verb: to call');");
>                         myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (English, 
> Japanese, MASU_Form, Definition)"
>                                                         + " VALUES ('call', 
> 'kakeru', 'kakemasu', 'verb: to wear');");
>                         myDB.execSQL("INSERT INTO "
>                                                         + MY_DATABASE_TABLE
>                                                         + " (English, 
> Japanese, MASU_Form, Definition)"
>                                                         + " VALUES ('call', 
> 'kakeru', 'kakemasu', 'verb: to
> hang');");*/
>
>                         //myDB.delete(MY_DATABASE_TABLE, "LastName" + "=" + 
> "'Ponce'",
> null);
>                         //myDB.delete(MY_DATABASE_TABLE, null, null);
>
>                         //Query for some results with Selection and 
> Projection.
>                         /*Cursor c = myDB.query(MY_DATABASE_TABLE,
>                                         new String[] {"FirstName, Age "}, 
> null,
>                                         null, null, null, null, "7");  */
>
>                         Cursor c = myDB.query(MY_DATABASE_TABLE,
>                                         new String[] {"English, Japanese , 
> MASU_Form, Definition"},
>                                         "Japanese" + "=" + "'kakeru'", null, 
> null, null, null, "7");
>
>                         // Get the indices of the Columns we will need
>                         int EnglishColumn = c.getColumnIndex("English");
>                         int JapaneseColumn = c.getColumnIndex("Japanese");
>                         int MASU_FormColumn = c.getColumnIndex("MASU_Form");
>                         int DefinitionColumn = c.getColumnIndex("Definition");
>
>                         // Check if our result was valid.
>                         if (c != null) {
>                                 //Check if at least one Result was returned.
>                                 if (c.moveToFirst()) {
>                                         int i = 0;
>                                         // Loop through all Results
>                                         do {
>                                                 i++;
>                                                 //Retrieve the values of the 
> Entry
>                                                  // the Cursor is pointing to.
>                                                 String english = 
> c.getString(EnglishColumn);
>                                                 String japanese = 
> c.getString(JapaneseColumn);
>                                                 String masu_form = 
> c.getString(MASU_FormColumn);
>                                                 String definition = 
> c.getString(DefinitionColumn);
>
>                                                 //Add current Entry to 
> results.
>                                                 results.add("(" + i + ") " + 
> english + ", " + japanese + ", " +
> masu_form + ", " + definition);
>
>                                         } while (c.moveToNext());
>                                 }
>                         }
>
>                 //} catch (FileNotFoundException e) {
>                 } finally {
>                         if (myDB != null)
>                                 myDB.close();
>                 }
>
>                 this.setListAdapter(new ArrayAdapter<String>(this,
>                                 android.R.layout.simple_list_item_1, 
> results));
>         }
>
> }
>
> ----------------------------------------------------------------------------------------------------------------------------------------
>
> would appreciate any help... thanks...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to