Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6724985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:45:12+00:00 2026-05-26T09:45:12+00:00

I want to use three previously created Activities in a ViewPager (with PagerAdapter) so

  • 0

I want to use three previously created Activities in a ViewPager (with PagerAdapter) so the user can scroll smoothly horizontally through them.
I followed a tutorial which worked great. The problem is in the tutorial they use TextViews to demonstrate. I already have finished Activities (of which the layouts are in XML files). I want to use these Activities in that slider now but it looks like I can only use Views for that.
I could not figure out how I have to change the code of the classes (from “implements Activity” to “extends View”) that I can use it in the slider.

The my current code looks like this:

public class HorizontalSliderBeispielActivity extends Activity {

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

       cxt = this;
       awesomeAdapter = new AwesomePagerAdapter();
       awesomePager = (ViewPager) findViewById(R.id.awesomepager);
       awesomePager.setAdapter(awesomeAdapter);
    }
...

then the inner class with the PageAdapter:

...
private class AwesomePagerAdapter extends PagerAdapter {

    public Object instantiateItem(View collection, int position) {
        TextView tv = new TextView(cxt);
        tv.setText("Bonjour PAUG " + position);
        tv.setTextColor(Color.WHITE);
        tv.setTextSize(30);

        view_01 = new SubmitCheatInstructions(cxt);

        ((ViewPager) collection).addView(tv, 0);
        ((ViewPager) collection).addView(view_01 , 1);

        return tv;
    }
}

Instead of that TextView “tv” I want to use Activities (i.e. SubmitCheatInstructions). Previously this class looked like:

public class SubmitCheatInstructions implements Activity {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.submitcheat_instructions);
}

}

but as far as I know I have to change it to

public class SubmitCheatInstructions extends View {
    ????
}

in order to be able to use it for the ViewPager.

My problem now is that I want to load the layout from the layout xml file (submitcheat_instructions.xml) into that view and not do everything in code. I could not figure out how I have to do this.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:45:12+00:00Added an answer on May 26, 2026 at 9:45 am

    I followed the same tutorial and like you i was unable to achieve this at first but after some tinkering and trial and error the following code worked like a charm:

            /**
         * Create the page for the given position. The adapter is responsible
         * for adding the view to the container given here, although it only
         * must ensure this is done by the time it returns from
         * {@link #finishUpdate()}.
         * 
         * @param container
         *            The containing View in which the page will be shown.
         * @param position
         *            The page position to be instantiated.
         * @return Returns an Object representing the new page. This does not
         *         need to be a View, but can be some other container of the
         *         page.
         */
        @Override
        public Object instantiateItem(View collection, int position) {
            View v = new View(PatientView.this.getApplicationContext());
            final LayoutInflater inflater = (LayoutInflater) PatientView.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            switch (position) {
            case 0:
                v = inflater.inflate(R.layout.patientp1,
                        (ViewGroup) null, false);
                ((Button) v.findViewById(R.id.pp1btnbck)).setOnClickListener(new OnClickListener() {
    
                    @Override
                    public void onClick(View arg0) {
                        finish();
                    }
                });
    
                break;
            case 1:
                v = inflater.inflate(R.layout.patientp2, null, false
                        );
                break;
            default:
    
                TextView tv = new TextView(PatientView.this.context);
                tv.setText("Page " + position);
                tv.setTextColor(Color.WHITE);
                tv.setTextSize(30);
                v = tv;
                break;
            }
            ((ViewPager) collection).addView(v, 0);
    
            return v;
        }
    

    Hope this helps, Good luck
    Shereef Marzouk

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables (individuals, groups & recordlabels) and want use the information between
I've created few apps and want to download them to my iPhone. Do i
I want to use an Abstract action for JFileChooser buttons because there will be
I want to use the pear mail extension to send SMTP authenticated emails. There
I want to use NSString from one UIView in another UIView . There are
I want to use geoJSON-formatted Data in my iPhone app. THere is a JSON
I want to use leiningen to build and develop my clojure project. Is there
I want to use ip camera as webcam in my application. is there an
I want to use a custom class that could handle querying easily. Are there
I want to use min(5,10) , or Math.max(4,7) . Are there functions to this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.