我正在使用asynctask來做一些xml的東西,我想在完成時更新textview,但我遇到以下問題,因此無法使用findViewById引用textview。在Asynctask中引用Textview
public class HTTPRequestTask extends AsyncTask<String , Void, String > {
@Override
protected String doInBackground(String... args) {
q = (TextView)findViewById(R.id.xmlData); //cannot resolve findViewbyId
然後我想更新後執行方法中的textview。
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);{
q.setText(s);
}
}
什麼是最直接的方式能夠設置postExecute方法中的文本?
你的代碼會導致**內存泄漏**在這種情況下,使用'WeakReference'。 – Enzokie