-7

I am making a dictionary application, the database contains more than 50k words.I am using a AutoCompleteTextView for showing the words while the user searches. I think it will be a huge task to load all the data and bind with AutoCompleteTextView at first, so I thought of loading data when keypress event happens.

Hitting the database for every button press event is also a bad idea as it is heavy, So is there any optimal way to do this ?. Since the app size matters I am not preferring to use Realm or any other database.

Any help will be appreciated

droidev
  • 7,352
  • 11
  • 62
  • 94
  • https://www.codeofaninja.com/2013/11/android-autocompletetextview-example-sqlite-database.html – Pratik Butani Jul 06 '15 at 04:55
  • http://makovkastar.github.io/blog/2014/04/12/android-autocompletetextview-with-suggestions-from-a-web-service/ – Pratik Butani Jul 06 '15 at 04:58
  • 1
    just use `SimpleCursorAdapter` with a `FilterQueryProvider`, thats all – pskink Jul 06 '15 at 06:03
  • look here: http://stackoverflow.com/a/19860624/2252830, all you need is to implement `runQuery()` method to return the `Cursor` from your sqlite database – pskink Jul 06 '15 at 06:50
  • and what? did it work? – pskink Jul 06 '15 at 09:18
  • @pskink yes, thanx :) – droidev Jul 07 '15 at 03:45
  • @Andrew Medico put on hold ??? why ?? – droidev Jul 11 '15 at 18:15
  • 1
    FYI, your question has been discussed [on meta](http://meta.stackoverflow.com/q/299026/849891). – Will Ness Jul 12 '15 at 19:58
  • 1
    I doubt this will be reopened, as it's clearly too broad (even given the rather permissive enforcing of SO guidelines in the Android tag). It is much better for you to show readers what you have, and then answers can be made to improve upon it. Please don't include direct requests for code in _any_ of your questions. – halfer Jul 13 '15 at 14:12

3 Answers3

5

You can use a filter like FilterQueryProvider with LIKE % command which will try to match character more efficiently rather than just pulling out the whole information.

Example,

 // select query
        String sql = "";
        sql += "SELECT * FROM " + tableName;
        sql += " WHERE " + fieldObjectName + " LIKE '%" + searchTerm + "%'";
        sql += " ORDER BY " + fieldObjectId + " DESC";
        sql += " LIMIT 0,5";

Source:

Android AutocompleteTextView with Database

Performance optimization tips:

Create index for your column and avoid scan operations by running a query analysis. Scan operations are much slower than search operations.

Source: The SQLite Query Optimizer Overview

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
3

Activity:

AutoCompleteTextView text;
String[] languages= {"Android ","java","IOS","SQL","JDBC","Web services"};

text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
ArrayAdapteradapter  = newArrayAdapter(this,android.R.layout.simple_list_item_1,languages);

text.setAdapter(adapter); 
text.setThreshold(1);
inmyth
  • 8,880
  • 4
  • 47
  • 52
Ashish Jaiswal
  • 804
  • 1
  • 9
  • 23
3

You can with the help of addTextChangedListener() do this in very few steps.

You can refer to this also.

RajSharma
  • 1,941
  • 3
  • 21
  • 34