小编Lak*_*aka的帖子

异步任务上 TextView 的 setText 完成

我想在我的 android 应用程序中使用 ksoap2 Web 服务返回一个特定的字符串。

Web 服务正在返回正确的值,但一旦任务完成,设置的文本就不会更新。我需要做一些事情(比如尝试打开导航抽屉)然后它会得到更新。有任何想法吗??

我的代码如下

// Calling the async class

protected void onResume() {
            try {
                super.onResume();
                new RetrieveTimeWS().execute();
            }
            catch (Exception e)
            {
                Log.e("Current Time", e.getMessage());
            }
        }
Run Code Online (Sandbox Code Playgroud)

以下是异步任务

class RetrieveTimeWS extends AsyncTask<Void, Void, String> {

        protected String doInBackground(Void... params) {
            String datetime = "";
            try {

                TextView TVcurrentTime = (TextView) findViewById(R.id.DateTimeNow);

                TVcurrentTime.setText("Loading...");
                datetime = getDateTimeClass.getDateTime();
                TVcurrentTime.setText(datetime);

            } catch (Exception e) {
                Log.e("Async Task - GetDateTime ", e.getMessage());
            }
            return datetime;
        }
    }
Run Code Online (Sandbox Code Playgroud)

文本字段显示“正在加载...”,直到我触摸屏幕上的任何组件。在 Web …

android textview android-asynctask

-1
推荐指数
1
解决办法
5320
查看次数

标签 统计

android ×1

android-asynctask ×1

textview ×1