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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:51:18+00:00 2026-06-09T01:51:18+00:00

I’m developing android app for a local newspapers and atm I’m trying to implement

  • 0

I’m developing android app for a local newspapers and atm I’m trying to implement swiping between articles. My main activity is HNappActivity and activity for article showing is AcrticleActivity. My problem is, that the swiping just wont work and I’m desperate because I have no idea whats wrong. Here’s code, where swiping is implemented:

public class ArticleActivity extends SherlockActivity {

int hnCatIndex, hnArtIndex;
WebView hnWebView;

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;

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

    hnCatIndex = getIntent().getExtras().getInt("catIndex", 0);
    hnArtIndex = getIntent().getExtras().getInt("artIndex", 0);
    Article article = Source.getInstance().getCategory(hnCatIndex).getArticle(hnArtIndex);

    hnWebView=(WebView)findViewById(R.id.webview);
    hnWebView.loadData(article == null ? "" : article.getBody(), "text/html",
                    "utf-8");
    gestureDetector = new GestureDetector(new MyGestureDetector());
    View articleview=(View) findViewById(R.id.article_main);

    articleview.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
}

    class MyGestureDetector extends SimpleOnGestureListener {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {


            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
                return false;
            }

            // right to left swipe
            if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            hnArtIndex++;
            Intent intent = new Intent(ArticleActivity.this.getBaseContext(), ArticleActivity.class);
            intent.putExtra("catIntext",hnCatIndex);
            intent.putExtra("artIndex",hnArtIndex);
            startActivity(intent);          
            ArticleActivity.this.overridePendingTransition(
            R.anim.slide_in_right,
            R.anim.slide_out_left
            );
            // right to left swipe
            }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                if (hnArtIndex==1) {
                    Intent intent = new Intent(ArticleActivity.this.getBaseContext(), HNappActivity.class);
                    startActivity(intent);
                    }
                else {
                    hnArtIndex--;
                    Intent intent = new Intent(ArticleActivity.this.getBaseContext(), ArticleActivity.class);
                    intent.putExtra("catIntext",hnCatIndex);
                    intent.putExtra("artIndex",hnArtIndex);
                    startActivity(intent);
                }
            ArticleActivity.this.overridePendingTransition(
            R.anim.slide_in_left, 
            R.anim.slide_out_right
            );
            }

            return false;
        }
            @Override
            public boolean onDown(MotionEvent e) {
                    return true;
            }
}   

}

  • 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-09T01:51:20+00:00Added an answer on June 9, 2026 at 1:51 am

    I didn’t even read the code, the problem is that you’re trying to swipe between activities.
    You should be trying to swipe between fragments, all fragments in the same activity.

    see:
    http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
    http://developer.android.com/reference/android/support/v4/view/ViewPager.html

    edit:

        private WebView hnWebView;
        @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.webViewFragment, null);
            hnWebView=(WebView)v.findViewById(R.id.webview);
            return v;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.