1

I'm tring to make an app like google+ desing, with titlepager and switch between activities horizontally. I've implemnted this library for pager (https://github.com/JakeWharton/Android-ViewPagerIndicator) and it works fine. But now, I dont know how to set diferent activities.

This is my main class

package com.rbrlnx.controles;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.viewpagerindicator.TitlePageIndicator;

public class ControlesDeAlcoholemiaActivity extends Activity {

    static final int NUMERO_DE_PAGINAS = 3;  


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Gestion del Pagindor
        ViewPagerAdapter adapter = new ViewPagerAdapter( this );
        ViewPager pager = (ViewPager)findViewById( R.id.viewpager );
        TitlePageIndicator indicator = (TitlePageIndicator)findViewById( R.id.indicator );
        pager.setAdapter( adapter );
        indicator.setViewPager(pager,2);


        //Gestion del ActionBar
        ActionBar ab;

    }

}  

and this is the pageradapter

package com.rbrlnx.controles;

import android.content.Context;
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.widget.LinearLayout;

import com.viewpagerindicator.TitleProvider;

public class ViewPagerAdapter extends PagerAdapter implements TitleProvider
{
    private static String[] titles = new String[]
    {
        "Comunes",
        "Listado",
        "Mapa"
    };    
    private final Context context;

    public ViewPagerAdapter( Context context )
    {
        this.context = context;
    }

    @Override
    public String getTitle( int position )
    {
        return titles[ position ];
    }

    @Override
    public int getCount()
    {
        return titles.length;
    }

    @Override
    public Object instantiateItem( View pager, int position )
    {


        LinearLayout v = (LinearLayout) LayoutInflater.from(this.context).inflate(R.layout.comunes, null);

        if (position == 0) {
            v = (LinearLayout) LayoutInflater.from(this.context).inflate(R.layout.comunes, null);
        } else if (position == 1) {
            v = (LinearLayout) LayoutInflater.from(this.context).inflate(R.layout.listado, null);
        } else {
            v = (LinearLayout) LayoutInflater.from(this.context).inflate(R.layout.mapa, null);
        }

        ((ViewPager) pager).addView(v, 0);

        return v;

    }

    @Override
    public void destroyItem( View pager, int position, Object view )
    {
    }

    @Override
    public boolean isViewFromObject( View view, Object object )
    {
        return view.equals( object );
    }

    @Override
    public void finishUpdate( View view ) {}

    @Override
    public void restoreState( Parcelable p, ClassLoader c ) {}

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public void startUpdate( View view ) {}
}

I can set the XML layout, but I don't know how to set the acitivy class. I think I must work with fragments but am not sure.

colymore
  • 11,776
  • 13
  • 48
  • 90
  • 1
    Yeah, for the ViewPager you can only use Fragments or Views, not Activities, for the pages. I'd recommend using Fragments. – Alex Curran Jan 27 '12 at 23:02
  • And can i use fragmets with maps? – colymore Jan 27 '12 at 23:03
  • not my area of expertise I'm afraid, but I'm not sure you can, although you'll want to double check that. If there is a MapView (as opposed to a MapActivity), you could use that as a page perhaps? Afraid I know very little about the Maps APIs, sorry. – Alex Curran Jan 27 '12 at 23:13
  • Ok, thanks :). Im reading for a fragments api – colymore Jan 27 '12 at 23:20
  • You can try this lib. Is very useful to handle ViewPager. – Chronos Jan 28 '12 at 00:12
  • Anyone have a code to show me how can i make that i want? If i use fragments, i divide the screen in to parts ( In all examples i look) but i want to set one activity for one page...same google+, or docs – colymore Jan 28 '12 at 00:24
  • I need to use FragmentPagerAdapter, anyone have a example? – colymore Jan 28 '12 at 00:38
  • There are samples in the API documentation and the support lib folder (`SDK/extras/android/support/v4/sample`). You can also look at the sample for ViewPagerIndicator as they all use fragments. – Jake Wharton Jan 28 '12 at 05:51
  • **Your answer is here:** http://stackoverflow.com/questions/9849138/android-pagerview-between-activities – Fouad Nov 15 '14 at 15:31
  • [You should use fragment. Your answer is here :][1] [1]: http://stackoverflow.com/questions/9849138/android-pagerview-between-activities – Fouad Nov 15 '14 at 15:34

0 Answers0