No, it’s not a duplicate.
I have a ListView (not the View in a layout xml file, the View as class) and want to display a view for the empty state.
The addView method isn’t available, simple replacing the ListView doesn’t work, because the parent is a ViewPager.
Any ideas?
Your pages for your
ViewPagerare being created by some form ofPagerAdapter. Presumably, from the way you are describing things, you rolled your ownPagerAdapter, rather than using one of the built-in fragment-based ones. And, presumably, thatPagerAdapteris returning aListViewfor one or more of the pages, for which you want an “empty view”.Simply put: you are going to have to change that
PagerAdapter. Instead of returning aListView, return something like aFrameLayoutcontaining yourListViewand your “empty view”. Whether you create those objects in Java or via inflating a layout resource is up to you. Along the way, callsetEmptyView()on theListViewto tie theListViewand the “empty view” together.