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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:32:04+00:00 2026-06-11T05:32:04+00:00

I am using a ViewPager with Dynamic Views as shown in this link .

  • 0

I am using a ViewPager with Dynamic Views as shown in this link. I am adding each page to the viewpager. The code to create each page and add it to the pager adapter is as follows

public View createPage( )
{   
TableLayout table = new TableLayout(mycontext);
TableRow row = new TableRow(mycontext);

for(int i=0; i <= num_of_views; i++)
{

        TableLayout catTable = new TableLayout(mycontext);

        TableLayout.LayoutParams params = new TableLayout.LayoutParams();   

        params.height = LayoutParams.MATCH_PARENT;

        TableRow catName = new TableRow(mycontext);
        catName.setGravity(0x03);
        catName.setLayoutParams(params);

        TextView cat = new TextView(mycontext);
        TableRow.LayoutParams RowParams= 
            new TableRow.LayoutParams(pixeltoDp(0),pixeltoDp(85));
        RowParams.weight = 1;
        cat.setLayoutParams(RowParams);
        cat.setPadding(35, 0, 5, 0);
        cat.setGravity(0x13);
        cat.setSingleLine(true);
        cat.setHorizontallyScrolling(true);
        cat.setFocusable(true);
        cat.setFocusableInTouchMode(true);
        cat.setLines(1);
        cat.setText(data.getCats().get(i).getName());
        cat.setTextColor(color);
        cat.setSelected(true);

        catName.addView(cat);
        catTable.addView(catName);
        for(int j=0; j < 5; j++)
        {
            TableRow trChild = new TableRow(mycontext);
            trChild.setLayoutParams(params);
            trChild.setGravity(0x11);
            for (int k=0; k<4; k++)
            {
                TextView app = new TextView(mycontext);
                TableRow.LayoutParams tableRowParams= 
                    new     TableRow.LayoutParams(pixeltoDp(0),pixeltoDp(80));
                margin = pixeltoDp(11);

                tableRowParams.weight = 1;
                app.setLayoutParams(tableRowParams);

                app.setGravity(0x11);
                app.setSingleLine(true);
                app.setTextSize(pixeltoDp(12));
                app.setTextColor(Color.BLACK);
                app.setTypeface(verdana);


                int pos = j+(k*5);
                if((pos < mysize))
                {
                        Drawable icon = getMyDrawable();

                        app.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
                        app.setText("some Name");
                        app.setTag(i+":"+pos);
                        app.setEllipsize(TextUtils.TruncateAt.END);
                        app.setOnClickListener(onMyClick);

                }

                trChild.addView(app);
            }
            catTable.addView(trChild);              
        }   
        TableRow.LayoutParams tableRowParams=
              new TableRow.LayoutParams
                  (TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.WRAP_CONTENT);
        margin = pixeltoDp(5);
        tableRowParams.setMargins(margin,0,margin, pixeltoDp(18));
        catTable.setLayoutParams(tableRowParams);       
}           
row.setGravity(0x03);
table.addView(row);     
return table;           
}

The OnClickListener for the textview in the page is as follows

    private View.OnClickListener onAppClick=new View.OnClickListener() {
    public void onClick(View v) {
        // TODO Auto-generated method stub
        String gettext = (String)v.getTag();
        String[] splittext = gettext.split(":");

        Log.d("TAG","Click Event is Triggered");
    }
};

The problem I am facing is that the viewpager slides when I swipe on the screen but if my finger starts the swipe from the text with the onclicklistener the page does not slide, also the click event is not called. If I click on the text view the click event is called. I am not able to figure why the viewpager in not flipping the pages if the swipe starts from the text view with click event.

To find out the reason for the bug I added a ontouchlistener to the viewpager and found that the touch event of the viewpager is called when the swipe happens on the part of the page where there is no text view and the touch event is not called at all if the swipe starts on top of the text view. If I remove the onclicklistener of the textview then the entire viewpager flips properly without any issue. So the problem is that the click event of the textview is stopping the touch events of the viewpager. Please tell me if I am doing something wrong in my create page code. The view which I create in this function is added to the viewpager through the pageadapter as shown in the tutorial I mentioned in the beginning.

  • 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-06-11T05:32:06+00:00Added an answer on June 11, 2026 at 5:32 am

    Finally I found that there is a bug in the latest version of ViewPager where a TextView with a click event, singleLine set as true and gravity set as center is not passing the touch events to the ViewPager if the finger is moved starting on the top of the textview. If we make the singleLine as false or remove the Center gravity then the events are passed to the ViewPager then it can fling. We can’t use both the center gravity and setsingleline(true) for the textview or a button with sinlgeline set as true. I have reported this as a bug here

    See the ‘apply single line’ source here: https://github.com/android/platform_frameworks_base/blob/7bfb1e7f46d2ed3df6cc467bccec95b5999d9cc4/core/java/android/widget/TextView.java#L7877

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

Sidebar

Related Questions

I'm using the following example to impliment my viewPager: http://code.google.com/p/viewpagerexample/issues/list The problem with this
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I have a project using a ViewPager which works correctly: I can page from
I got a tab menu using a ViewPager . Each tab contains fragments from
I'm trying to add dynamic content to my mvc application. I'm using Steven Sanderson
I have a working viewpager example using code I got from a tutorial. The
I am using ASP.NET 4 and MVC and trying to add code to handle
I am using a ViewPager from the compatibility library. I get this exception quite
I am making an app in which i am using ViewPAger and my code

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.