0
try {
    answerField.setText("Unscrambling...This may take a minute");
    BufferedInputStream(getAssets().open("wordlist.txt"));
    BufferedInputStream[] textfile = new BufferedInputStream[28];
    for(int i = 0; i<28; i++){
        textfile[i] = new BufferedInputStream(getAssets().open(i+1+".txt"));
        }
    answerField.setText(Unscramble.go(tField.getText()+"", textfile));

我的问题是 answerField.setText("Unscrambling...This may take a minute");

如果代码是原样,那么这一行将什么也不做,但是,如果我去掉代码的最后一行 answerField.setText(Unscramble.go(tField.getText()+"", textfile)); 它可以找到并且TextView说“Unscrambling ...这可能需要一分钟”

目标是让它在程序完成解密之前拥有该消息,然后它将产生结果。

任何帮助将不胜感激,因为我不知道我在做什么或为什么会发生这种情况。

4

1 回答 1

2

setText问题是 UI 在第一次调用和第二次调用之间没有更新。正如@AVD 提到的,一种解决方案是使用Toast.

我认为推荐的另一种解决方案是使用AsyncTask. 这里的想法是将您的文本设置为 in 中的“Unscrambling”消息onPreExecute,然后在 中运行您的主要任务doInBackground,最后将文本设置为 in 中的Unscramble.*字符串onPostExecute

我在上面提供的文档链接有一个很棒的AsyncTask代码,可以操纵它来处理任何事情。

于 2012-07-10T03:19:43.503 回答