ListView shows empty message briefly before data is loaded

让人想犯罪 __ 提交于 2019-12-05 01:58:25

The provided answers were on the right track. I indeed had to set the TextView to invisible, but the correct location is in onCreateLoader:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args)
{
  mListView.getEmptyView().setVisibility(ListView.GONE);

  return new CursorLoader(getActivity(), CONTENT_URI, null, null, null, null);
}

Also, it's not necessary to make the empty view visible again: this is done automatically by the framework.

How about adding the following to the TextView

android:visibility="invisible"

to the XML layout file, and then making the TextView visible if required.

You will have to set the TextView visibility to invisible, and only once you have loaded the data --that is onLoadComplete-- you will have to set it as the empty view for the ListView by doing setEmptyView(textView);

If you do it in XML or you do it before your results are loaded, the view will be shown since the list is effectively empty. So you have to wait until the results are loaded to set the empty view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!