Hello,

As a learning project for myself, I read the contents of a text file
into an SQL database, and would like to make its contents accessible
via a SimpleCursorAdapter.

My code to read the file and store it in the DB is:

public class DictionarySQLAutoComplete extends Activity
{
  public static final String AUTHORITY = "com.xxx.android.examples";
  public static final Uri CONTENT_URI = Uri.parse("content://" +
AUTHORITY + "/dictionarysqlautocomplete");

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    DictionaryDbAdapter aDbHelper = new DictionaryDbAdapter( this );
    aDbHelper.open();

    // Fill the DB with the file contents
    AssetManager assetManager = getResources().getAssets();
    InputStream inStream =assetManager.open("filename.txt");
    DataInputStream dataInStream = new DataInputStream(inStream);
    BufferedReader bufReader = new BufferedReader(new InputStreamReader
(dataInStream));

    String aFileLine = null;
    while( ( aFileLine = bufReader.readLine() ) != null )
    {
      // Copy read line to next item to the dictionary
      long result = aDbHelper.createDictionaryEntry(aFileLine, "empty
for now");
    }
    bufReader.close();

    // Get the cursor for the full DB contents query
    Cursor aCursor = mDbHelper.fetchAllDictionaryEntries();

    //Create the auto-complete text widget
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById
(R.id.edit);

    // Create the adapter from the database cursor
    mFrom = new String[] { DictionaryDbAdapter.KEY_ROWID};
    mTo = new int[] { android.R.id.text1 };
    SimpleCursorAdapter adapter = new SimpleCursorAdapter( this,
            android.R.layout.simple_dropdown_item_1line,
            aCursor, mFrom, mTo );
}

The DictionaryDbAdapter class is based on the one used in the Notepad
tutorial sample.

I would like to associate the cursor to the content provider
CONTENT_URI, so that I can link its adapter to the
AutoCompleteTextView. Can I do it?

Thanks,
Paul
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to