Android display a button with OnTouchListener -
i have button disappears 3 seconds after press on it. make visible again touching screen.
public class mainactivity extends activity { runnable buttonrunnable; handler buttonhandler = new handler(); protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final button button=(button)findviewbyid(r.id.mybutton); buttonrunnable = new runnable() { public void run() { button.setvisibility(view.gone); } }; button.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { buttonhandler.postdelayed(buttonrunnable, 3000); } }); } private ontouchlistener buttonontouchlistener = new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { final button button=(button)findviewbyid(r.id.mybutton); final linearlayout linearlayout=(linearlayout)findviewbyid(r.id.mylinearlayout); linearlayout.setclickable(true); linearlayout.setonclicklistener(new onclicklistener() { public void onclick(view view) { button.setvisibility(view.visible); } }); return true; } }; }
i able hide button after 3 seconds cannot make visible again.
you need reference parent container view, , make sure call setclickable(true) on it. then, attach click handler view, , in click handler, call button.setvisibility(view.visible);
Comments
Post a Comment