Note that there are some explanatory texts on larger screens.

plurals
  1. POViewPager not showing correct View
    primarykey
    data
    text
    <p>I'm using the V4 compatibility JAR. I have a ViewPager that shows information about some bands. When I create the PagerAdapter, I pass it an ArrayList of Band objects.</p> <p>In the emulator, it always shows shows the 2nd band in the ArrayList's information first. When I flip to the last view, the view always has no data. When I flip back and forth, the data then gets really buggy.</p> <p><strong>BandsActivity</strong></p> <pre><code>private ViewPager mBandsPager; private BandsPagerAdapter mBandsPagerAdapter; private static final String TAG = "Paging"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.awesomepager); // Build a couple bands; ArrayList&lt;Band&gt; bands = new ArrayList&lt;Band&gt;(); bands.add(new Band(1, "Led Zeppelin")); bands.add(new Band(37, "Brand New")); bands.add(new Band(49, "Jay-Z")); mBandsPagerAdapter = new BandsPagerAdapter(this, bands); mBandsPager = (ViewPager) findViewById(R.id.awesomepager); mBandsPager.setAdapter(mBandsPagerAdapter); } </code></pre> <p><strong>BandsPagerAdapter</strong></p> <pre><code>private Context mCtx; private ArrayList&lt;Band&gt; mBands; public BandsPagerAdapter(Context ctx, ArrayList&lt;Band&gt; bands) { mCtx = ctx; mBands = bands; } @Override public int getCount() { return mBands.size(); } @Override public Object instantiateItem(View collection, int position) { // Inflate and create the view LayoutInflater layoutInflater = (LayoutInflater)mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.featured_bands_layout, null); // Build UI TextView name = (TextView)collection.findViewById(R.id.featured_band_name); // Populate UI with band data Band band = mBands.get(position); if(name != null) { name.setText("Name: " + band.getName() + ", Pos: " + position); } // Add View to the ViewPager collection ((ViewPager)collection).addView(view,0); return view; } @Override public void destroyItem(View collection, int position, Object view) { ((ViewGroup) collection).removeView((View)view); } @Override public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Override public void finishUpdate(View arg0) {} @Override public void restoreState(Parcelable arg0, ClassLoader arg1) {} @Override public Parcelable saveState() { return null; } @Override public void startUpdate(View arg0) {} </code></pre> <p>Any suggestions? I saw a mention of implementing ViewPager.SimpleOnPageChangeListener, but didn't see how it could be used properly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload