3

我在刷新 ListViews 时遇到问题。我有一个 TabActivity 调用另一个 TabActivity(SubTabActivity) 调用 ListActivity。我的 ListView 从 Web 服务器的 XML 文件中获取数据。在我的自定义标题中,我有一个按钮来重新加载/刷新 ListView。当我更改 subTab 时,我调用 onTabChanged-Method 用其他数据重绘列表。

我现在的问题是我只能在进行第一次选项卡更改之前刷新 ListView。更改 Tap 后,我只能刷新第二个列表。当我回到第一个列表时,我无法刷新两者。我只能从我的 XML 文件中获取新数据,但我无法显示它。我尝试了 invalidate()、invalidateViews() 和 notifyDataSetChanged(),但没有什么能解决这个错误。

我的 AsyncTask 刷新

private static class ReloadNews extends AsyncTask<Void, Void, Void>
{   
    @Override
    protected void onPreExecute()
    {
        MenuActivity.startProgress();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        News.getNews(News.url);

        myref.runOnUiThread(new Runnable() 
        {
            @Override
            public void run() 
            {
                // TODO Auto-generated method stub  
                if(SubTabMenuActivity.subMenuTabHost.getCurrentTabTag().equals("FestivalNews"))
                {
                    adapter = new NewsAdapter(myref, News.getFestivalNews());
                    newsList.setAdapter(adapter);
                }
                else if(SubTabMenuActivity.subMenuTabHost.getCurrentTabTag().equals("RennNews"))
                {
                    adapter = new NewsAdapter(myref, News.getRegattaNews());
                    newsList.setAdapter(adapter);
                }
            }   
        });     
        return null;
    }

    @Override
    protected void onPostExecute(Void result)
    {
        MenuActivity.stopProgress();
    }
}

知道为什么在 TabChange 之后它不起作用吗?

编辑:

10-25 05:58:28.264: D/dalvikvm(272): GC_EXPLICIT freed 8K, 51% free 2725K/5511K,   external 410K/517K, paused 241ms
10-25 05:58:33.104: D/dalvikvm(310): GC_EXPLICIT freed 236K, 45% free 3366K/6087K, external 410K/517K, paused 53ms
10-25 05:58:35.281: D/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol
10-25 05:58:38.163: D/dalvikvm(345): GC_EXPLICIT freed 106K, 44% free 3521K/6215K, external 410K/517K, paused 79ms
10-25 05:58:43.153: D/dalvikvm(360): GC_EXPLICIT freed 325K, 51% free 2720K/5511K, external 410K/517K, paused 54ms
10-25 05:58:57.233: I/System.out(433): ADaPter
10-25 05:58:57.243: I/System.out(433): ADaPter
10-25 05:58:57.263: I/System.out(433): ADaPter
10-25 05:58:57.273: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.273: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.293: I/System.out(433): ADaPter
10-25 05:58:57.303: I/System.out(433): ADaPter
10-25 05:58:57.313: I/System.out(433): ADaPter
10-25 05:58:57.323: I/System.out(433): ADaPter
10-25 05:58:57.333: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.333: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.433: I/System.out(433): ADaPter
10-25 05:58:57.453: I/System.out(433): ADaPter
10-25 05:58:57.483: I/System.out(433): ADaPter
10-25 05:58:57.493: D/dalvikvm(433): GC_CONCURRENT freed 1274K, 62% free 3322K/8647K, external 2400K/2689K, paused 4ms+5ms
10-25 05:58:57.523: I/System.out(433): ADaPter
10-25 05:58:57.533: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.533: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.553: I/System.out(433): ADaPter
10-25 05:58:57.563: I/System.out(433): ADaPter
10-25 05:58:57.573: I/System.out(433): ADaPter
10-25 05:58:57.593: I/System.out(433): ADaPter
10-25 05:58:57.593: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.603: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.623: I/System.out(433): ADaPter
10-25 05:58:57.633: I/System.out(433): ADaPter
10-25 05:58:57.643: I/System.out(433): ADaPter
10-25 05:58:57.653: I/System.out(433): ADaPter
10-25 05:58:57.663: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.663: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.693: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.693: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.693: I/System.out(433): ADaPter
10-25 05:58:57.713: I/System.out(433): ADaPter
10-25 05:58:57.723: I/System.out(433): ADaPter
10-25 05:58:57.733: I/System.out(433): ADaPter
10-25 05:58:57.743: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.743: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.793: I/System.out(433): ADaPter
10-25 05:58:57.803: I/System.out(433): ADaPter
10-25 05:58:57.813: I/System.out(433): ADaPter
10-25 05:58:57.813: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.813: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.933: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.933: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:57.943: I/System.out(433): ADaPter
10-25 05:58:58.003: D/dalvikvm(433): GC_CONCURRENT freed 890K, 61% free 3439K/8647K, external 2240K/2689K, paused 8ms+4ms
10-25 05:58:58.003: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.003: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.013: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.013: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.023: I/System.out(433): ADaPter
10-25 05:58:58.073: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.073: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.083: I/System.out(433): ADaPter
10-25 05:58:58.083: I/System.out(433): ADaPter
10-25 05:58:58.103: I/System.out(433): ADaPter
10-25 05:58:58.113: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.113: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.123: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.123: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.143: I/System.out(433): ADaPter
10-25 05:58:58.433: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.453: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.453: D/skia(433): --- SkImageDecoder::Factory returned null
10-25 05:58:58.453: D/skia(433): --- SkImageDecoder::Factory returned null

这是我的 LogCat 正常,同时填充列表以及在 tabchange 之前调用 refresh 时。

以下 logcat 部分是在 tabchange 并再次调用 refresh 之后。

10-25 05:59:01.493: D/dalvikvm(433): GC_FOR_MALLOC freed 293K, 58% free 3686K/8647K, external 2240K/2689K, paused 30ms
10-25 05:59:01.493: I/dalvikvm-heap(433): Grow heap (frag case) to 8.655MB for 524304-byte allocation
10-25 05:59:01.523: D/dalvikvm(433): GC_FOR_MALLOC freed 256K, 58% free 3942K/9223K, external 2240K/2689K, paused 31ms
10-25 05:59:01.923: D/dalvikvm(433): GC_FOR_MALLOC freed 532K, 56% free 4094K/9223K, external 2240K/2689K, paused 27ms
10-25 05:59:02.313: D/dalvikvm(433): GC_CONCURRENT freed 862K, 54% free 4319K/9223K, external 2240K/2689K, paused 5ms+6ms
10-25 05:59:02.943: D/dalvikvm(433): GC_CONCURRENT freed 989K, 51% free 4609K/9223K, external 2240K/2689K, paused 7ms+3ms
10-25 05:59:03.473: D/dalvikvm(433): GC_CONCURRENT freed 1478K, 52% free 4447K/9223K, external 2240K/2689K, paused 7ms+7ms
10-25 05:59:03.783: W/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4073bca0

我注意到适配器不会将数据加载到列表中。如果我调用 adapter.count(); 我可以看到他已经获得了新数据,但他不再将其绘制到列表中。

添加另一个 logTag 后,我注意到我的 Adapter 的构造函数被调用但不是 getView 方法。我的 ListView 是否有可能失去适配器的焦点?

4

2 回答 2

0

好的,我找到了自己的解决方案。我已将不同的列表拆分为不同的 Activtiys,并为每个 mainTab 创建了自己的 subTab Activity。我对这个解决方案并不感到自豪,但它确实有效。

于 2012-10-26T14:00:38.630 回答
0

 newsList.setAdapter(adapter);

添加这个:

adapter.notifyDataSetChanged();

祝你好运

于 2012-10-24T15:21:30.433 回答