Andrew Andrew - 7 months ago 25
Android Question

SwipeView change the content of 2 pages

I've created a new activity with swipe views, and added some code.

I have now two swipeable pages, but with the same content, how can i change the content of the second swipe page.

Do I have to create a new activity or just to redirect it to another xml?

import java.util.Locale;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

public class ListItemClicked extends ActionBarActivity {

static Bundle extras;

SectionsPagerAdapter mSectionsPagerAdapter;
static ImageLoader imageLoader;
static DisplayImageOptions options;

ViewPager mViewPager;

protected void onCreate(Bundle savedInstanceState) {

mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

extras = getIntent().getExtras();

mViewPager = (ViewPager) findViewById(;

//Setup the ImageLoader, we'll use this to display our images
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
imageLoader = ImageLoader.getInstance();

//Setup options for ImageLoader so it will handle caching for us.
options = new DisplayImageOptions.Builder()


public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(, menu);
return true;

public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

return id == || super.onOptionsItemSelected(item);


public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {

public Fragment getItem(int position) {
return PlaceholderFragment.newInstance(position + 1);

public int getCount() {
return 2;

public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section4).toUpperCase(l);
case 1:
return getString(R.string.title_section5).toUpperCase(l);
return null;

public static class PlaceholderFragment extends Fragment {

private static final String ARG_SECTION_NUMBER = "section_number";

public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
return fragment;

public PlaceholderFragment() {

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)

View rootView = inflater.inflate(R.layout.fragment_list_item_clicked, container, false);

TextView pDate = (TextView) rootView.findViewById(;
pDate.setText( extras.getString("pdate") );

TextView ptitle = (TextView) rootView.findViewById(;

TextView pnText = (TextView) rootView.findViewById(;
pnText.setText( extras.getString("pText"));

//Setup a listener we can use to swtich from the loading indicator to the Image once it's ready
ImageLoadingListener listener = new ImageLoadingListener(){

public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub


public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub


public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
// i/ndicator.setVisibility(View.INVISIBLE);
// iconImg.setVisibility(View.VISIBLE);
public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
// TODO Auto-generated method stub



//Load the image and use our options so caching is handled.
final ImageView iconImg = (ImageView) rootView.findViewById(;
imageLoader.displayImage( extras.getString("pImage"), iconImg, options, listener);

return rootView;



Answer Source

based on the page number you get from Placeholder Fragment you can set the new content