• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Android display a button with OnTouchListener

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a button that disappears 3 seconds after I press on it. I would like to make it visible again by touching the screen.



I am able to hide the button after 3 seconds but I cannot make it visible again.

I've asked the same question on another forum and got told that I need to get a reference to the parent container view, call setClickable(true) on it. Then, attach another click handler to that view, and in that click handler, call button.setVisibility(View.VISIBLE);

I am a bit struggling with this part and I'm not sure how I can implement it as I'm very new to Android.

Thank you.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like decent advice. Let's see how to implement it:

Alexander Pavlov wrote:...I've asked the same question on another forum and got told that I need to get a reference to the parent container view ...


You already know how to do that since you do it for the button...

...call setClickable(true) on it. ...


Looks like a simple method call.

... Then, attach another click handler to that view, and in that click handler, call button.setVisibility(View.VISIBLE);


Another thing you know how to do because you do essentially the same thing with the button.

So what is the problem you are having?
 
Alexander Pavlov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done everything that I was advised to do and this is my updated code:



However, the button still doesn't turn visible when I touch anywhere on the screen. I know the problem is somewhere in my OnTouchListener method but as I'm very new to programming I just can't figure out what it is.
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have an OnTouchListener, but where do you register it? When do you think it would get called? Count the number of listeners you have in your code. Which one(s) do you think get executed? If you aren't sure, then try adding Log.d(...) calls and looking in LogCat to see what gets executed.
 
Alexander Pavlov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply, Steve. I've added a call for OnTouchListener in my onCreate method right after button.SetOnClickListener. So that way if I touch anywhere on the LinearLayout, it should call "buttonOnTouchListener" and execute all the code in it. However, I still can't get the button to turn visible.

 
Alexander Pavlov
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have fixed the problem. There was too much code in my OnTouchListener that I didn't need. Thanks for your help, Steve!

 
reply
    Bookmark Topic Watch Topic
  • New Topic