-1

如何更新片段中的视图?

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 函数,我想要在我的视图中的项目,但我不知道如何。也许还有一个微调器!这是完美的!

谢谢,托马斯

4

1 回答 1

0

您必须ListView在布局中使用 a 并onPostExecute()为其设置适配器

ListView list = (ListView) getView().findViewById(R.id.list);
list.setAdapter(new ArrayAdapter<RssItem>(getActivity(), android.R.layout.simple_list_item_1, result));
于 2013-08-18T20:50:46.160 回答