如何更新片段中的视图?
package at.example.gacapp;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.List;
/**
* Created by Thomas on 18/08/13.
*/
public class News extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.overview, container, false);
GetRSSDataTask rss = new GetRSSDataTask();
rss.execute("http://www.grazer-ac.at/index.php?format=feed&type=rss");
return root;
}
private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem> > {
@Override
protected List<RssItem> doInBackground(String... urls) {
// Debug the task thread name
Log.d("ITCRssReader", Thread.currentThread().getName());
try {
// Create RSS reader
RssReader rssReader = new RssReader(urls[0]);
// Parse RSS, get items
return rssReader.getItems();
} catch (Exception e) {
Log.e("ITCRssReader", e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(List<RssItem> result) {
TextView itcItems = (TextView) getView().findViewById(R.id.tom);
itcItems.setText("Hans");
}
}
}
如何更新片段中的视图?我的问题是 onPostExecute 函数,我想要在我的视图中的项目,但我不知道如何。也许还有一个微调器!这是完美的!
谢谢,托马斯