English 中文(简体)
恢复应用程序时有时间将项目添加到适应器中, 列表仍为空, 列表却是空的 View List
原标题:ListView empty despite items added to adapter sometime when resuming application

在市场上我有一个应用程序,有一个我似乎无法解决的错误。今天,我追踪到了以下方法。

public void updateDealList(ArrayList<Deal> deals) {
    // first call or showing bookmakrs (also gets called other times when adapter is null)
    if (dealListAdapter == null || showingBookmarks || !dealListAdapter.moreDealsToDownload()) { 
        dealListAdapter = new EndlessDealListAdapter(getActivity(),
                R.layout.deal_list_item, deals);
        setListAdapter(dealListAdapter);
        listView = getListView();
        if (getActivity().findViewById(R.id.right_fragment_container)!=null){ // if tablet
            listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            listView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
        }
        showingBookmarks=false;
        Log.d("UPDATE_DEAL_LIST", "Notified list  created new" + dealListAdapter.getCount());
        return; //PROBLEM OCCURS WHEN APP COMES IN HERE AFTER RESUMING
    }
    dealListAdapter.getDealListAdapter().clear();
    for (Deal d: deals){
        dealListAdapter.getDealListAdapter().add(d);
        Log.d("UPDATE_DEAL_LIST", "added " + d.title);
    }
    dealListAdapter.notifyDataSetChanged();
    Log.d("UPDATE_DEAL_LIST", "Notified list " + dealListAdapter.getCount());
}

此方法通过一个交易对象的阵列列表, 交易对象从互联网上被调走。 当应用程序首次打开时, 数据会从互联网上被调出, 并且上述方法被调用为 ListFrashment 设置新的适配器。 当用户要求更多交易时, 也使用此方法 。

我面临的问题是,列表有时会认为它空虚地忽略了包含交易的适配器。 当其设备内存率低时, 使用似乎会恢复应用程序( 我想部分应用程序已被清除了 ) 。 此方法被调用, 交易列表是空的, 从而创建了新的列表并添加了交易 。 尽管发生了这种情况, 列表还是空的, 用户必须强制关闭应用程序才能再次工作 。

下一行显示方法在输入是否输入时的标记, 并在适应器中添加21项交易。 不幸的是, 列表对用户是空的 。

05-23 01:52:32.879: D/UPDATE_DEAL_LIST(3478): Notified list  created new21
最佳回答

一个想法(相当长的镜头:)

If the app itself wasn t killed, just the activity, the system tries to recreate the activity s last state, calling the onRestoreInstanceState(). This method will not be called if the app was killed - so this is one of the big differences between the two.

ListAffactivity 超越了 Restore Instance State () 。 它确保了列表在继续之前就已经存在。 如果列表不存在, 它会从默认位置向它充气 。

如果您在 Resume () 中重新设置内容View (), 试图将其移到 Create () 上, 这可能解决问题 。

我可以帮更多忙, 如果我看到活动代码。

问题回答

您可以尝试以下一个或多个选项

  • 请在设置列表适配器之前先拨打 setListShown( false)

  • Otherwise, do
    setListShown(false);
    setListAdapter(null);

  • 否则, < code> 是否请求Layout ()





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签