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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:39:18+00:00 2026-05-24T17:39:18+00:00

In my code i m implementing swipe using the HorizontalScrollView for that i got

  • 0

In my code i m implementing swipe using the HorizontalScrollView for that i got a proper working code , its working fine to swipe left or right now my problem is i wand to show a dynamic page no. for that i added some extra code in that but its not working the code is below

public class PaginationLayout extends LinearLayout {

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

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

        setOrientation(LinearLayout.VERTICAL);

        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;
                }
            }
        });
        super.addView(mScroll);

    }

    @Override
    public void addView(View child) {
        mScroll.addView(child);
    }

    @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);
            }
        }
    }


    public void previous() {
        mPageActive = (mPageActive > 0) ? mPageActive - 1 : 0;
        mScroll.smoothScrollTo(mPageActive * mScroll.getWidth(), 0);
    }


    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 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;
        }
    }
public void setPage(int noOfPageToScroll   ) {

    int pageWidth = mScroll.getWidth(); //problem is coming in this line its coming 0 always
    int nextPage = (noOfPageToScroll + 1) * pageWidth;

    Log.v("trace","Pagination.setPage() called with noOfPageToScroll = "+noOfPageToScroll+"and nextPage =  "+nextPage+ " and pageWidth = "+pageWidth);
    mScroll.smoothScrollTo(nextPage, 0);
}
}

//————-inside the my activity i m using this java file

public void setUpViews(){

    try {
        TableLayout table = new TableLayout(getBaseContext());
        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);
        LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

              //throught inflator i m adding multiple dynamic Views in row
        paginationLayout.addView(table);

        // set pagination layout
        setContentView(paginationLayout);

     //here i m calling want to go to specific page so i m calling 
                 paginationLayout.setPage(gotopageno );
             //but every time is showing the first page and of scroll view and the  log 06-24 16:38:39.156: VERBOSE/trace(894): setPage() called with noOfPageToScroll = gotopageno and nextPage =  0 and pageWidth = 0

// as much i understand the problem is that i m not getting the mscroll.width() == 0 it is called before draw view or may be some other reason

    } catch (Exception e) {
        Log.e("Error", "Problem in setUpViews() code 4 ");
        e.printStackTrace();
    }

}

//Please help me and ignore any grammer mistake. Thanks in advance

  • 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-24T17:39:19+00:00Added an answer on May 24, 2026 at 5:39 pm

    I solved this problem using the viewflipper as in HorrizontalScrollView the View size is becoming very big.

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

Sidebar

Related Questions

implementing publishActivity in PHP using the REST API using this code: $activity = array(
When implementing the Strategy Pattern, where does one put the code that determines which
I'm implementing a small HTTP server with Ruby using Mongrel. My code currently looks
Can anyone provide any sample code/instructions for implementing draggable pins in OS 4.0 using
I am working on a project in eclipse that when I launch using the
I am implementing Code Generation for WindowsForm control at Design-Time, using a Custom CodeDomSerializer.
I'm learning to use the mkreversegeocoder classes and have got it working using the
I am using the JanRain library, and implementing code very similar to their server
I'm implementing some code generators, i would like to know if there's any way
What best practices should be observed when implementing HDL code? What are the commonalities

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.