我正在 updateCandidates()
中开发软键盘。我的问题是如何在 Composing 有一些单词时检索每个文本,然后在候选 View 中加载我的字典。
图片:
如何加载单词。
图片
感谢您与我分享有关它的任何信息。
最佳答案
解决方案
你可以像这样制作方法:
public ArrayList<String> readFile() {
ArrayList<String> list = new ArrayList<String>();
try {
AssetManager am = getAssets();
InputStream data = am.open("data.txt");
InputStreamReader dataInputStream = new InputStreamReader(data);
BufferedReader reader = new BufferedReader(dataInputStream);
String each = null;
while ((each = reader.readLine()) != null) {
list.add(each);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
编辑软键盘
pickSuggestionManually()
public void pickSuggestionManually(int index) {
if (mCompletionOn && mCompletions != null && index >= 0 && index < mCompletions.length) {
CompletionInfo ci = mCompletions[index];
getCurrentInputConnection().commitCompletion(ci);
if (mCandidateView != null) {
mCandidateView.clear();
}
updateShiftKeyState(getCurrentInputEditorInfo());
} else if (mComposing.length() > 0) {
// If we were generating candidate suggestions for the current
// text, we would commit one of them here. But for this sample,
// we will just commit the current text.
mComposing.setLength(index);
mComposing = new StringBuilder(mCandidateList.get(index) + " ");
commitTyped(getCurrentInputConnection());
}
}
这里重要updateCandidates()
ArrayList<String> listData = readFile();
System.out.println("Sonu Kumar: " + listData);
if (!mCompletionOn) {
if (mComposing.length() > 0) {
ArrayList<String> list = new ArrayList<String>();
// list.add(mComposing.toString());
for (int j = 0; j < listData.size(); j++) {
String str = mComposing.toString().toLowerCase();
if (listData.get(j).startsWith(str)) {
list.add(listData.get(j));
}
}
mCandidateList = list;
setSuggestions(list, true, true);
} else {
setSuggestions(null, false, false);
}
}
感谢
关于android - 如何从软键盘中候选 View 上显示的 Assets 中读取文本字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33035399/