erdemhayir erdemhayir - 3 months ago 17
Android Question

Android Dictionary app

I am going to create an android dictionary application which goal is to translate my mother language (Zazaki) to Turkish.

I have 2 documents which have a format like below:

Zazaki to Turkish word docs
ban: ev ====> home

Turkish to Zazaki
ev: ban, ├že ===> home

In my mind, first taking word before colon as key, after colon as value.

Then putting it into a database.

My question is:

"Do I have to do this operation for every time?

How can I make this database available for every download by not importing the word list documents into my database"?


First, if you have excel, it's quite easy to make a word document into a databse , by splitting by ' ' and deleting the resulting coloumns you don't need. You can then export it, e.g. into a .csv file.

For your request, I would use the following pseudo-code as a guide for my code:

int currIndex = 0;
string key, value;
    currIndex = find('=');
    key = getWordBeforeCurrentIndex();
    currIndex = find('>');
    value = getWordAfterCurrentIndex();
    myDictionary.Add(key, value);

Make that into real code and voila - you got yourself an app parsing a document into a dictionary.

If you know that your document has an exact format like:

ev ====> home

word2 ===> translation2

word3 ===> translation3

You can of course leverage this and go

Dictionary myDict = new HashTable<string, string>();
InputStream wordDictionary = getResources().openRawResource(R.raw.wordDictionary);
DataInputStream myDIS = new DataInputStream(wordDictionary);

ArrayList<string> lines = new ArrayList<Lines>();
string currLine;
//Read document into arraylist:
while((myLine=myDIS.readline())!=null) list.add(myLine);
//Take each line, add left word as key, add right word as value:
foreach(line : lines){
    myDict.add(line.substring(0, line.indexOf(" ")), line.substring(line.indexOf(" ", line.indexOf(" ")+1));