Reputation: 126
I have a long list of words and their definitions in a Google spead sheet. What would be the best way to load this data into a content provider.
Upvotes: 0
Views: 94
Reputation: 8255
You should check out the Android Sample Project called "Searchable Dictionary" from the sdk samples. You can download the samples using the Android sdk manager. The sample does something similar to what you are trying to accomplish.
They have a file called definitions.txt with the words and their definitions in a folder called "raw" under resources. Then in their SqliteOpenHelper class they are loading the words in the onCreate method with in a separate thread.
Here is a snippet of the method they are running.
private void loadWords() throws IOException {
Log.d(TAG, "Loading words...");
final Resources resources = mHelperContext.getResources();
InputStream inputStream = resources.openRawResource(R.raw.definitions);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
try {
String line;
while ((line = reader.readLine()) != null) {
String[] strings = TextUtils.split(line, "-");
if (strings.length < 2) continue;
long id = addWord(strings[0].trim(), strings[1].trim());
if (id < 0) {
Log.e(TAG, "unable to add word: " + strings[0].trim());
}
}
} finally {
reader.close();
}
Log.d(TAG, "DONE loading words.");
}
Upvotes: 1