저를 도와주세요하지만, 앱의 에셋 폴더에 txt 파일로 '맞춤'사전을 추가 할 수 있습니다. 이 link에는 약 20,000 단어에서 200,000 단어까지 여러 단어 목록이 있습니다. Google을 통해 더 많은 목록을 찾을 수 있습니다.
그 후, 당신은 TXT 파일을 읽고 단어 길이를 일치하는 경우 배열 목록에 추가 할 수 있습니다. 그런 다음 임의의 단어를 사전 목록에서 선택할 수 있습니다. 다음 코드는 사전을 생성하고 사전에서 임의의 단어를 선택합니다.
private ArrayList<String> dictionary;
private int wordLength; //Set elsewhere
private void createDictionary(){
dictionary = new ArrayList<String>();
BufferedReader dict = null; //Holds the dictionary file
AssetManager am = this.getAssets();
try {
//dictionary.txt should be in the assets folder.
dict = new BufferedReader(new InputStreamReader(am.open("dictionary.txt")));
String word;
while((word = dict.readLine()) != null){
if(word.length() == wordLength){
dictionary.add(word);
}
}
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
dict.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Precondition: the dictionary has been created.
private String getRandomWord(){
return dictionaryList.get((int)(Math.random() * dictionaryList.size()));
}