android-当ListFragment为空时,不会显示SetEmptyText()
作者:互联网
我正在使用ListFragments ..当列表为空时,我想使用setEmptyText(),但它没有显示它继续显示进度,它一直显示进度栏,我不知道确切的位置包含此列表的布局这是我的代码
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
new getData().execute();
}
private class getData extends AsyncTask<Void, Void, ArrayList<Object>> {
@Override
protected ArrayList<Object> doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
artists = new ArrayList<Object>();
artists = loadArtists("taqwa.xml");
return loadXml("taqwa.xml");
} catch (XmlPullParserException e) {
e.printStackTrace();
Utils.log("XML exception", "true");
return null;
} catch (IOException e) {
e.printStackTrace();
Utils.log("IOException", "true");
return null;
}
}
@Override
protected void onPostExecute(ArrayList<Object> result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (result != null) {
ListAdapter ladapter = new ListAdapter(getActivity(),
R.layout.list_row, null, artists, 3);
setListAdapter(ladapter);
} else {
setEmptyText("not found wallahi!");
}
}
}
如您所见,我不使用包含@ id / android:list之类的布局来添加@ id / android:empty ..我仅将列表项发送到baseAdapter
解决方法:
看起来您没有列表视图的适配器,所以setEmptyText()不起作用.
标签:android-listfragment,android 来源: https://codeday.me/bug/20191030/1969581.html