Textview不会立即在循环中更新

时间:2017-11-30 19:26:24

标签: android android-studio textview

我有一个for循环,每个循环开始时我都会更新textView。但是代码完全执行后textView始终会更新。我有一个想法,我可以在另一个线程更新textView但我不知道这是否会有所帮助。有什么方法可以立即更新吗?

我正在第一个循环的第一行更新textView。

public void searchWords(View v) {
    String chars = inSearch.getText().toString().toUpperCase();
    ArrayList<String> found = new ArrayList<>();

    for (int i = 0; i < wordList.size(); i++) {
        loadingAtT1.setText(wordList.get(i));
        String left = chars;
        boolean ok = true;
        for (int j = 0; j < wordList.get(i).length(); j++) {
            boolean cont = left.contains(String.valueOf(wordList.get(i).charAt(j)));
            if (cont) {
                left = left.replaceFirst(String.valueOf(wordList.get(i).charAt(j)), "");
            } else {
                ok = false;
                break;
            }
        }
        if (ok) found.add(wordList.get(i));
    }

    for (int i = 0; i < found.size(); i++) {
        Log.i("result", found.get(i));
    }

    String toTextView = "";
    int display = 0;
    for (int i = 0; i < found.size(); i++) {
        if (wordLength.getText().length() > 0) {
            if (found.get(i).length() == Integer.parseInt(wordLength.getText().toString())) {
                toTextView += found.get(i) + "\n";
                display++;
            }
        } else {
            toTextView += found.get(i) + "\n";
            display++;
        }

    }

    resultTextView.setText(toTextView);
    Toast.makeText(getApplicationContext(), "Displaying " + display + " from " +
            found.size() + " words found to match.", Toast.LENGTH_SHORT).show();
}

提前谢谢。

0 个答案:

没有答案
相关问题