Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All I needed to do was move :</p> <p><code>thisIsWhatBreaks = (LinearLayout)findViewById(R.id.layoutThatsAlwaysNull);</code></p> <p>to the case which inflates the current layout.xml inside of instantiateItem() of the PagerAdapter.</p> <p>My problem with the nullpointerexceptions was that all of my views were being acted upon in onCreate(). I had to move all of the views from onCreate() to the case statement inside of instantiateItem();</p> <p>See the corrected code below....just in case anyone else runs into this problem....</p> <pre><code>public class SimpleViewPagerActivity extends Activity { LinearLayout thisIsWhatBreaks; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager); myPager.setAdapter(adapter); myPager.setCurrentItem(2); //REMOVE THE LINEAR LAYOUT FROM BEING INSTANTIATED HERE! } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { thisIsWhatBreaks.setBackgroundColor(Color.BLACK); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ thisIsWhatBreaks.setBackgroundColor(Color.RED); } } private class MyPagerAdapter extends PagerAdapter { public int getCount() { return 5; } public Object instantiateItem(View collection, int position) { view = new View(MainHome.this); final LayoutInflater inflater = (LayoutInflater) MainHome.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0 : view = inflater.inflate(R.layout.farleft, null); thisIsWhatBreaks= (LinearLayout)v.findViewById(R.id.layoutThatUsedToAlwaysBeNull); ***Now you can modify thisIsWhatBreaks*** thisIsWhatBreaks.setBackgroundColor(Color.black); break; case 1: view = inflater.inflate(R.layout.farright, null); break; default : break; } ((ViewPager) collection).addView(v,0); return v; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public void finishUpdate(View arg0) { // TODO Auto-generated method stub } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public void restoreState(Parcelable arg0, ClassLoader arg1) { // TODO Auto-generated method stub } @Override public Parcelable saveState() { // TODO Auto-generated method stub return null; } @Override public void startUpdate(View arg0) { // TODO Auto-generated method stub } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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