0

I am currently developing android keyboard. I want to make word dictionary for the keyboard to suggest the words with respect to the user inputs. But dictionary is not an activity so, I cannot use getAssets() method to read text file if I put the text file in asset folder. Is there a way to read text document in Android Studio?

Zoe
  • 27,060
  • 21
  • 118
  • 148

1 Answers1

0

This is a list which should be stored in SharedPreferences or Database and should be loaded into memory(RAM) whenever the keyboard pops up. Getting from assets is an IO operation and its usages should be minimal.

If you want to read data from your .txt file, then you can prepare a JSON or XML and use getAssets() to read that JSON during initial startup of the "Application" and after that.

[UPDATE] As requested in the answer

Here's how you can read JSON data from the text file.

and how to parse JSON.

Daksh Gargas
  • 3,498
  • 2
  • 23
  • 37