Hi, you don't need to modify bindView and convertToString, just conserve the variable columnIndex, because in the constructor of MyCursorAdpter you can pass which column index you want to search. So you just need to modify the sql query in runQueryOnBackgroundThread, replace the "name" with "_id". Don't forget to modify setThreshold of AutoCompleteTextView if you want to search "_id", because "_id" 's value has only one character.
On 17 mar, 11:26, aljo <[email protected]> wrote: > Thanks... your program worked... > > Thank you for your help... > > Just one question... If what I understand is correct, your program > queries only the first column of the table... If I query the second > column which is the "_id" column, it still looks into the "name" > column and displays the content of the name column in the autocomplete > textview. So i have to change the ((TextView) view).setText > (cursor.getString(columnIndex)) and return cursor.getString > (columnIndex) to ((TextView) view).setText(cursor.getString(1)) and > return cursor.getString(1)... > I don't know if what I did to modify the code was the correct way or > do you have a better way? > > it now looks like this... > > �...@override > public void bindView(View view, Context context, Cursor > cursor) { > ((TextView) view).setText(cursor.getString(1)); > } > > @Override > public String convertToString(Cursor cursor) { > Log.i("info", " convertToString "); > return cursor.getString(1); > } > > @Override > public Cursor runQueryOnBackgroundThread(CharSequence > constraint) { > if (constraint != null) { > String selection = "_id like \'" + constraint.toString() > +"%\'"; > return sqlite.query("test", null, selection, null, > null, null, null); > } > else { > return null; > } > } > > sorry if im such a noob.... > > On Mar 13, 5:28 pm, roland <[email protected]> wrote: > > > Hi, i made a sample of using a AutoCompleteTextView to showing names > > which are saved in a database. > > > Here is the link of > > project:http://0467525716.free.fr/Android/AutocompleteTest.zip > > > I hope it helps. > > > On 10 mar, 04:26, aljo <[email protected]> wrote: > > > > i already saw that thread but i still can't understand some of the > > > codes... i don't know how to incorporate my database in that code... > > > how can i import my db... > > > > public ContactListAdapter(Context context, Cursor c) { > > > super(context, c); > > > Log.d("exp", "******************* A VER EHJEE > > > *****************"); > > > mDb = new Database > > > (context); > > > <------- (is this where i will put my DB?) > > > mDb.open(); > > > Log.d("exp", "******************* A VER PUES 100 > > > *****************"); > > > } > > > > private static final String[] PEOPLE_PROJECTION = new String[] > > > <----- (is this where autocomplete extracts its data?) > > > { > > > Database.KEY_REASON, > > > Database.KEY_VALUE, > > > Database.KEY_TAX > > > }; > > > > sorry guyz... im kinda new on this whole thing.... > > > tnx for any of your help... > > > > On Mar 5, 6:42 pm, roland <[email protected]> wrote: > > > > > Check this > > > > out,http://groups.google.com/group/android-developers/browse_thread/threa... > > > > > On 4 mar, 07:22, aljo <[email protected]> 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 SQLitedatabaseprogram.. but i don't know how to use > > > > > theautocompletefunction to access mydatabase... here's my code: > > > > > > -------------------------------------------------------------------------------------------------------------------------------------- > > > > > > packagedatabase.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 classDatabaseextends 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 theDatabase(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 theDatabase. > > > > > 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) { > > > > > > > ... > > plus de détails » --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

