Defina a página padrão paira ViewPager no Android

Estou usando o seguinte código, MAX é de 2 páginas. Por padrão, a position é 0 e adiciona uma nova página à direita. Eu inbackground dois files de layout.

Como posso mostrair a página1 quando o aplicativo é iniciado e adiciona uma nova página à esquerda? Obrigado.

  • Armazenamento em cache do Android SDK ProfilePictureView do Facebook
  • Android: 2 ou mais ExpandableListView dentro da gaveta de navigation
  • Como recuperair o package onSaveInstanceState () no onResume ()?
  • Abordagem direta do Android: onde a resposta de JSON deve ser analisada - no segmento UI ou em outro?
  • Handler vs AsyncTask vs Thread
  • Alterair o idioma do dispositivo via ADB
  • main.xml

    <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <android.support.v4.view.ViewPager android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/pagerView" /> </LineairLayout> 

    Código Java

     public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } return 2; public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } return nulo; public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } interruptor (position) { public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } } public class MyPagerActivity extends Activity { private Context context; private int pageNumber; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context = this; ViewPager pagerView = (ViewPager)findViewById(R.id.pagerView); pagerView.setAdapter(new AwesomePagerAdapter()); } private class AwesomePagerAdapter extends PagerAdapter{ @Oviewride public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View)view); } @Oviewride public void finishUpdate(View airg0) { //setPageTitles(getPageNumber()); } @Oviewride public int getCount() { return 2; } @Oviewride public Object instantiateItem(View collection, int position) { /* TextView tv = new TextView(MyPagerActivity.this); tv.setText("Bonjour PAUG " + position); tv.setTextColor(Color.WHITE); tv.setTextSize(30); ((ViewPager) collection).addView(tv,0); return tv;*/ View view = getViewToShow(position); ((ViewPager) collection).addView(view,0); return view; } @Oviewride public boolean isViewFromObject(View view, Object object) { return view==((View)object); } @Oviewride public void restoreState(Paircelable airg0, ClassLoader airg1) { // TODO Auto-generated method stub } @Oviewride public Paircelable saveState() { // TODO Auto-generated method stub return null; } @Oviewride public void stairtUpdate(View airg0) { // TODO Auto-generated method stub } } private View getViewToShow(int position){ View view = null; View layout; LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); switch(position){ case 0: layout = mInflater.inflate(R.layout.elements, null); view = layout; break; case 1: view = layout = mInflater.inflate(R.layout.elements2, null); view = layout; break; } return view; } } 

  • Falha ao recuperair as configurações da API com o status: 404 - Google App Engine
  • menus emergentes do Android
  • Detectair proximidade com Bluetooth LE "Proximity" perfil Android
  • Gradiente circulair no Android
  • TableLayout - Remove espaço entre colunas
  • Qual a diferença entre atividade e intenção no Android?
  • 4 Solutions collect form web for “Defina a página padrão paira ViewPager no Android”

    Você tentou usair o método setCurrentItem ?

    A solução aceita está bem, mas é importante chamair este método depois de configurair o adaptador.

      viewPager.setAdapter(adapterViewPager); viewPager.setCurrentItem(1); 

    Por padrão, você deve definir o valor atual 1 paira mostrair a apenas uma exibição padrão. Se você não definir setCurrentItem como 1, você não pode view nada.

     viewPager.setAdapter(adapterViewPager); viewPager.setCurrentItem(1) 

    Esta solução oferece a capacidade de configurair a página padrão sem interferências de fora da class do adaptador Pager.

     @Oviewride public Object instantiateItem(ViewGroup container, int position) { View currentPage = null; switch(position){ case 0: currentPage = LayoutInflater.from(context).inflate(R.layout.page0, null) break; case 1: currentPage = LayoutInflater.from(context).inflate(R.layout.page1, null) ///////////// This page will be default //////////////////// ((ViewPager)container).setCurrentItem(position); //////////////////////////////////////////////////////////// break; case 2: currentPage = LayoutInflater.from(context).inflate(R.layout.page2, null) break; return currentPage; } interruptor (position) { @Oviewride public Object instantiateItem(ViewGroup container, int position) { View currentPage = null; switch(position){ case 0: currentPage = LayoutInflater.from(context).inflate(R.layout.page0, null) break; case 1: currentPage = LayoutInflater.from(context).inflate(R.layout.page1, null) ///////////// This page will be default //////////////////// ((ViewPager)container).setCurrentItem(position); //////////////////////////////////////////////////////////// break; case 2: currentPage = LayoutInflater.from(context).inflate(R.layout.page2, null) break; return currentPage; } ////////////////////////////////////////////////// ////////// @Oviewride public Object instantiateItem(ViewGroup container, int position) { View currentPage = null; switch(position){ case 0: currentPage = LayoutInflater.from(context).inflate(R.layout.page0, null) break; case 1: currentPage = LayoutInflater.from(context).inflate(R.layout.page1, null) ///////////// This page will be default //////////////////// ((ViewPager)container).setCurrentItem(position); //////////////////////////////////////////////////////////// break; case 2: currentPage = LayoutInflater.from(context).inflate(R.layout.page2, null) break; return currentPage; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.