사용자로부터 데이터를 가져 와서 데이터베이스의 결과를 표시하는 앱이 있습니다. 해당 데이터베이스에서 데이터를 ArrayList로 푸시합니다. 예를 들어 사용자가 문장 (예 : 'Hello world')을 입력하면 앱은 데이터베이스의 레코드를 반복하고 뭔가를 발견하면 사용자에게 단어를 찾음을 표시합니다. 이와 같이 :arraylist 결과가 두 배로 늘림
모호한 단어 : 세계 의미 : 세계의 의미.
는 여기에 내가 일하고 있어요 코드입니다 :
private DBHelper dbHelper;
Cursor cursor;
ArrayList<String> colWords = new ArrayList<String>();
ArrayList<String> colMeanings = new ArrayList<String>();
String[] words;
String[] meanings;
ok = (Button) findViewById (R.id.button1);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//checkAmbiguousWord();
dbHelper = new DBHelper(MainActivity.this);
try {
dbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
dbHelper.openDataBase();
} catch (SQLException sqle) {
throw sqle;
}
cursor = dbHelper.getAllWords();
for(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()) {
colWords.add(cursor.getString(1));
colMeanings.add(cursor.getString(2));
}
checkAmbiguousWord();
}
});
}
private void checkAmbiguousWord(){
final String textToCheck = text.getText().toString();
List<Integer> ambiguousIndexes = findAmbiguousWordIndexes(textToCheck);
view.setText(!ambiguousIndexes.isEmpty() ?
ambigousIndexesToMessage(ambiguousIndexes) : "No ambiguous word/s found.");
}
/**
* @param text checked for ambiguous words
* @return the list of indexes of the ambiguous words in the {@code words} array
*/
private List<Integer> findAmbiguousWordIndexes(String text) {
final String lowerCasedText = text.toLowerCase();
final List<Integer> ambiguousWordIndexList = new ArrayList<Integer>();
words = (String[]) colWords.toArray(new String[colWords.size()]);
meanings = (String[]) colMeanings.toArray(new String[colMeanings.size()]);
for (int i = 0; i < words.length; i++) {
if (lowerCasedText.contains(words[i].toLowerCase())) {
ambiguousWordIndexList.add(i);
}
}
return ambiguousWordIndexList;
}
public String ambigousIndexesToMessage(List<Integer> ambiguousIndexes) {
// create the text using the indexes
// this is an example implementation
StringBuilder sb = new StringBuilder();
for (Integer index : ambiguousIndexes) {
sb.append("Ambiguous words: ");
sb.append(words[index] + "\nMeaning: " + meanings[index] + "\n");
sb.append(" ");
}
return sb.toString();
}
하지만 내 문제는 결과가 추가됩니다 모든 시간 I 입력 같은 안녕하세요입니다.
모호한 단어 : 세계 의미 : 세계 모호한 단어의 의미 : 세계 의미 : 세계
잘못 내 코드에서 무엇의 의미는? 나는 Java에 익숙하지 않으므로 잘못된 코드 줄을 찾는 데 도움이 필요합니다. 어떤 도움이라도 대단히 감사합니다. 미리 감사드립니다.
이 떨어지고 테이블 : (당신의 버튼을 "확인"을 클릭 한 번으로) 각 호출 후 – robotoaster
아니요, 어떤 테이블도 놓치지 않고 있습니다. – Dunkey