【发布时间】:2015-02-06 13:26:37
【问题描述】:
我想在我的 android 应用程序中使用 ksoap2 网络服务返回一个特定的字符串。
Web 服务正在返回正确的值,但任务完成后设置的文本没有得到更新。我需要做一些事情(比如尝试打开导航抽屉)然后它会得到更新。有什么想法吗??
我的代码如下
// Calling the async class
protected void onResume() {
try {
super.onResume();
new RetrieveTimeWS().execute();
}
catch (Exception e)
{
Log.e("Current Time", e.getMessage());
}
}
下面是异步任务
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;
}
}
只有在我触摸屏幕上的任何组件之前,文本字段才会显示“正在加载...”。 Web服务返回文本后,如何将文本视图更改为所需的字符串。
提前致谢。
拉克斯。
【问题讨论】:
-
在 onPostExecute(); stackoverflow.com/questions/8369539/…
标签: android android-asynctask textview