1

In a ViewPager is there a way to display a spinner if there is nothing available to display? I.e. the PagerAdapter associated does not have any items?

Jim
  • 18,826
  • 34
  • 135
  • 254
  • Can you explain more why you want a *spinner* in place of an empty pager? My first thought is that you need to do a check inside `onCreate` to see if `myPagerAdapter.getCount() == 0`. – AdamMc331 Mar 20 '15 at 16:07
  • @McAdam331:Because I the items may be available in a few seconds so that I have the widget in place showing a spinner and when the items are available show them – Jim Mar 20 '15 at 16:10

1 Answers1

2

I would do a check for this inside the onCreate method of the activity where you implement the ViewPager. For example, let's say if you do have items you want to show the layout that includes the ViewPager, but if you don't you want to display a splash screen, or a simple layout with a spinner, try this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(mAdapter.getCount() == 0)
        setContentView(R.layout.my_empty_view);
    else{
        setContentView(R.layout.my_pager_view);
    }    
}
AdamMc331
  • 16,492
  • 10
  • 71
  • 133
  • And how do I show with this approach a layout with a spinner? Sorry I am newbie in android – Jim Mar 20 '15 at 16:23
  • With this approach, you will have to create an XML file with the layout you want. If you want it to be just a spinner, you can do that. I recommend a layout that has at least an additional textview that gives a warning or states that you are still pulling information. That is strictly suggestion, not a requirement by any means. – AdamMc331 Mar 20 '15 at 16:24
  • But how can this be created? Searching in google for layout and spinner it seems that spinner is meant as some kind of selection list and what I need is a wait/progress like spinner – Jim Mar 20 '15 at 18:35
  • A `Spinner` in android is kind of like a combo box or another sort of drop down list. Are you sure that's what you want to show? Or did you mean some sort of rotating symbol? – AdamMc331 Mar 20 '15 at 18:47
  • I think I found it (tag ProgressBar?) http://stackoverflow.com/questions/12559461/how-to-show-progress-barcircle-in-an-activity-having-a-listview-before-loading – Jim Mar 20 '15 at 18:51