Bien, tengo lo primero hecho y lo segundo también, pero no se cómo unirlo.
Dentro del código del Fragment, dónde añado el código que carga todos los layout?
El código del fragment es este
Código:
package es.androcode.viewpager; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.json.JSONArray; import org.json.JSONObject; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import es.androcode.viewpager.prueba.R; public class PruebaViewPagerActivity extends Activity { private ViewPager columnas; private static int NUM_COLUMNAS = 3; private Context cxt; private ColumnasAdapter miAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); cxt = this; miAdapter = new ColumnasAdapter(); columnas = (ViewPager) findViewById(R.id.columnas); columnas.setAdapter(miAdapter); } private class ColumnasAdapter extends PagerAdapter { @Override public int getCount() { return NUM_COLUMNAS; } @Override public Object instantiateItem(View collection, int position) { LinearLayout v = (LinearLayout) LayoutInflater.from(cxt).inflate(R.layout.columna1, null); if (position == 0) { v = (LinearLayout) LayoutInflater.from(cxt).inflate(R.layout.columna1, null); } else if (position == 1) { v = (LinearLayout) LayoutInflater.from(cxt).inflate(R.layout.columna2, null); } else { v = (LinearLayout) LayoutInflater.from(cxt).inflate(R.layout.columna3, null); } ((ViewPager) collection).addView(v, 0); return v; } @Override public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((LinearLayout) view); } @Override public boolean isViewFromObject(View view, Object object) { return view == ((LinearLayout) 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) { } } }