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 6803305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:19:42+00:00 2026-05-26T19:19:42+00:00

I know how to develop the tab activity using xml layout and also i

  • 0

I know how to develop the tab activity using xml layout and also i know how to do paging in android as is seen in android market application

but i am not getting how to merge this paging concept with tab activity and how to create tabactivity from the java code :

see the code below i use for paging using linear layout :

sample.java

public class Sample extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // creates the Pagination Layout
        PaginationLayout paginationLayout = new PaginationLayout(this);
        paginationLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

        // creates content only for sample
        TableLayout table = new TableLayout(this);
        table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        table.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);

        TableRow row = new TableRow(this);
        row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        table.addView(row);

        TableRow row2 = new TableRow(this);
        row2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        table.addView(row2);

        for(int i = 0; i< 50;i++){
            Button button = new Button(this);
            button.setText("Button " + i);
            if (i%2==0) {
                row.addView(button);
            } else {
                row2.addView(button);
            }
        }

        // add the content in pagination
        paginationLayout.addView(table);
        // set pagination layout
        setContentView(paginationLayout);
    }
}

and the code for pagination layout is :

public class PaginationLayout extends LinearLayout {

    private int mPageActive = 0;
    private HorizontalScrollView mScroll;
    private LinearLayout mBar;

    public PaginationLayout(Context context) {
        super(context);

        setOrientation(LinearLayout.VERTICAL);

        // creates the class that will control the gestures and apply it in the
        // scroll
        final GestureDetector mGestureDetector = new GestureDetector(new MySimpleOnGestureListener());

        mScroll = new HorizontalScrollView(context);
        mScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        mScroll.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                if (mGestureDetector.onTouchEvent(event)) {
                    return true;
                } else {
                    return false;
                }
            }
        });

        // creates Previous and Next buttons
        Button btnPrevious = new Button(getContext());
        btnPrevious.setLayoutParams(new LayoutParams(150, LayoutParams.FILL_PARENT));
        btnPrevious.setText("Previous");
        btnPrevious.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                previous();
            }
        });

        Button btnMid = new Button(getContext());
        btnMid.setLayoutParams(new LayoutParams(150, LayoutParams.FILL_PARENT));
        btnMid.setText("Mid");
        btnMid.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                next();
            }
        });

        Button btnNext = new Button(getContext());
        btnNext.setLayoutParams(new LayoutParams(150, LayoutParams.FILL_PARENT));
        btnNext.setText("Next");
        btnNext.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                next();
            }
        });

        // bar that include the buttons
        mBar = new LinearLayout(getContext());
        mBar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        mBar.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        mBar.setBackgroundColor(Color.GRAY);
        mBar.addView(btnPrevious);
        mBar.addView(btnNext);
        //mBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.android_1080p));
        mBar.setVisibility(LinearLayout.INVISIBLE);

        // add bar and scroll in the super (LinearLayout)
        super.addView(mBar);
        super.addView(mScroll);
    }

    /**
     * All that the user include is added in the scroll
     */
    @Override
    public void addView(View child) {
        mScroll.addView(child);
    }

    /**
     * Controls if the top bar should appear or not
     */
    @Override
    protected void onSizeChanged(int arg0, int arg1, int arg2, int arg3) {
        super.onSizeChanged(arg0, arg1, arg2, arg3);
        View chield = mScroll.getChildAt(0);
        if (chield != null) {
            if (chield.getMeasuredWidth() > getWidth()) {
                mBar.setVisibility(LinearLayout.VISIBLE);
            } else {
                mBar.setVisibility(LinearLayout.INVISIBLE);
            }
        }
    }

    /**
     * does the effect "back a page"
     */
    public void previous() {
        mPageActive = (mPageActive > 0) ? mPageActive - 1 : 0;
        mScroll.smoothScrollTo(mPageActive * mScroll.getWidth(), 0);
    }

    /**
     * does the effect "forward a page"
     */
    public void next() {
        int pageWidth = mScroll.getWidth();
        int nextPage = (mPageActive + 1) * pageWidth;
        if (nextPage - mScroll.getScrollX() <= pageWidth) {
            mScroll.smoothScrollTo(nextPage, 0);
            mPageActive++;
        } else {
            mScroll.smoothScrollTo(mScroll.getScrollX(), 0);
        }
    }

    /**
     * Private class that controls the gestures, forward or back a page.
     */
    private class MySimpleOnGestureListener extends SimpleOnGestureListener {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            if (e1 != null && e2 != null) {
                if (e1.getX() - e2.getX() > 0) {
                    // forward...
                    next();
                    return true;
                } else if (e2.getX() - e1.getX() > 0) {
                    // back...
                    previous();
                    return true;
                }
            }

            return false;
        }
    }
}
  • 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-26T19:19:43+00:00Added an answer on May 26, 2026 at 7:19 pm

    I’ve found this it’s maybe helpful 😉

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

Sidebar

Related Questions

I'm learning to develop applications for Android but I need to know the XML
I know a little about SNMP, but not enough. I need to develop an
Friends, I like to know using which version of Android SDK we can develop
I know how to develop in Android and use the Apache HTTP lib, but
I'm trying to develop an Audio Capture application using the AudioRecord class from android
I want to know if I can develop graphics application with DirectX using C#?
I'd be very keen to know how to develop a social game on android
i would like to know if i can develop a OpenSocial based application for
I want to develop google desktop search like application, I want to know that
I want to develop a web application, like an online scheduler. (Yes I know

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.