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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:14:07+00:00 2026-06-05T03:14:07+00:00

In the code below the problem i m facing is that in onTouchListener method

  • 0

In the code below the problem i m facing is that in onTouchListener method both if and else part is getting executed each time. Anyone have idea why is it happening like that? and aim of my project is on touch event on anywhere in on the webview the dock layout must appear on another touch it must disappear.Can anyone help regarding this?

Thanks in advance ..

     public class MathiasdockActivity extends Activity {
    /** Called when the activity is first created. */
    RelativeLayout upperdock,parent;
    LinearLayout tocbottom,tocparent;
    boolean flag=true;
    WebView wv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        parent=(RelativeLayout) findViewById(R.id.rl1);
        upperdock=(RelativeLayout) findViewById(R.id.upperdock);
        tocparent=(LinearLayout) findViewById(R.id.tocparent);
        tocbottom=(LinearLayout) findViewById(R.id.linearLayout3);
        upperdock.setVisibility(RelativeLayout.INVISIBLE);
        tocparent.setVisibility(LinearLayout.INVISIBLE);
        tocbottom.setVisibility(LinearLayout.INVISIBLE);
        wv = (WebView) findViewById(R.id.webView1);  
        wv.loadUrl("file:///android_asset/hotspot/07-03.html");
        wv.getSettings().setJavaScriptEnabled(true);


        wv.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                    if(flag)
                    {
                            Toast toast1 = Toast.makeText(getBaseContext(), Boolean.toString(flag) + "if", 1000);
                            toast1.show();
                            upperdock.bringToFront();
                            tocparent.bringToFront();
                            tocbottom.bringToFront();
                            upperdock.setVisibility(RelativeLayout.VISIBLE);
                            tocparent.setVisibility(LinearLayout.VISIBLE);
                            tocbottom.setVisibility(LinearLayout.VISIBLE);
                            flag=false;
                    }
                    else
                    {
                            Toast toast2 = Toast.makeText(getBaseContext(), Boolean.toString(flag) + "else", 1000);
                            toast2.show();
                            wv.bringToFront();
                            upperdock.setVisibility(RelativeLayout.INVISIBLE);
                            tocparent.setVisibility(LinearLayout.INVISIBLE);
                            tocbottom.setVisibility(LinearLayout.INVISIBLE);
                            flag=true;  

                    }

                    return flag;
            }
        });
    }
   }
  • 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-05T03:14:09+00:00Added an answer on June 5, 2026 at 3:14 am

    Its because OnTouchListener calls continuously, so you need to check that user touches first time by MotionEvent.ACTION_DOWN

    wv.setOnTouchListener(new OnTouchListener() {
    
            public boolean onTouch(View v, MotionEvent event) {
    
            if(event.getAction()== MotionEvent.ACTION_DOWN)
            {
                    if(flag)
                    {
                       Toast toast1 = Toast.makeText(getBaseContext(), Boolean.toString(flag) + "if", 1000);
                       toast1.show();
                       upperdock.bringToFront();
                       tocparent.bringToFront();
                       tocbottom.bringToFront();
                       upperdock.setVisibility(RelativeLayout.VISIBLE);
                       tocparent.setVisibility(LinearLayout.VISIBLE);
                       tocbottom.setVisibility(LinearLayout.VISIBLE);
                       flag=false;
                    }
                    else
                    {
                       Toast toast2 = Toast.makeText(getBaseContext(), Boolean.toString(flag) + "else", 1000);
                       toast2.show();
                       wv.bringToFront();
                       upperdock.setVisibility(RelativeLayout.INVISIBLE);
                       tocparent.setVisibility(LinearLayout.INVISIBLE);
                       tocbottom.setVisibility(LinearLayout.INVISIBLE);
                       flag=true;
                    }
              }
                  return flag;
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem I am facing with below code is that whenever I try to
Below are my code for jQuery UI, the problem I am facing is that
Brand new to android and facing a weird problem.Check out the code below FirstActivity.java:
I am facing a problem with the code below which is run on Visual Studio 2008.
The code below is (hopefully) a minimized testcase of my original problem. I'm trying
The code below is working, but with a problem I do not understand. When
What is the problem with my code below? It's not returning any items even
I am having a very specific problem in JQuery The code below is used
I've a problem with CakePHP __() function. Please see the code below : $options
I have a problem sending POST request with VB6. The code below works properly

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.