java - no response to setVisibility -


i'm trying write app buttons trigger sound , want buttons visible when pressed add setvisibility method when press button there no response.

my code is:

import android.app.activity; import android.media.mediaplayer; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.imagebutton; import android.widget.relativelayout;  import static android.view.view.invisible; import static android.view.view.visible;  public class mainactivity extends activity {  relativelayout background; imagebutton btn; mediaplayer sound;  @override protected void onpause() {     super.onpause();     sound.release(); }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     sound = mediaplayer.create(this, r.raw.kick);     btn = (imagebutton) findviewbyid(r.id.btn1);     btn.setvisibility(invisible);     btn.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             mediaplayer mp = mediaplayer.create(getapplicationcontext(), r.raw.kick);                 btn.setvisibility(visible);             mp.start();          }     });     }  } 

xml

<relativelayout        xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity" android:id="@+id/background" android:background="@drawable/fuckyou" android:orientation="horizontal">   <imagebutton     android:id="@+id/btn1"     android:layout_width="109dp"     android:layout_height="89dp"     android:scaletype="fitxy"     android:layout_margintop="26dp"     android:src="@mipmap/oneeee"     android:background="@null"     android:contentdescription="@null"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_marginleft="1dp" /> 

logcat shows following:

06-20 02:02:57.249  28473-28473/sp.umavibe.com.sp404 i/art﹕ not late-   enabling -xcheck:jni (already on) 06-20 02:02:57.249  28473-28473/sp.umavibe.com.sp404 i/art﹕ late-enabling jit 06-20 02:02:57.251  28473-28473/sp.umavibe.com.sp404 i/art﹕ jit created code_cache_capacity=2mb compile_threshold=1000 06-20 02:02:57.673  28473-28484/sp.umavibe.com.sp404 i/art﹕ background sticky concurrent mark sweep gc freed 8726(388kb) allocspace objects, 0(0b) los objects, 0% free, 10mb/10mb, paused 6.293ms total 56.655ms 06-20 02:02:57.695  28473-28473/sp.umavibe.com.sp404 e/mediaplayer﹕ should have subtitle controller set 06-20 02:02:57.710  28473-28489/sp.umavibe.com.sp404 d/openglrenderer﹕ use egl_swap_behavior_preserved: true 06-20 02:02:57.714  28473-28473/sp.umavibe.com.sp404 d/﹕ hostconnection::get() new host connection established 0xab1704a0, tid 28473 06-20 02:02:57.728  28473-28473/sp.umavibe.com.sp404 e/mediaplayer﹕ should have subtitle controller set 06-20 02:02:57.775  28473-28489/sp.umavibe.com.sp404 d/﹕ hostconnection::get() new host connection established 0xab170540, tid 28489 06-20 02:02:57.804  28473-28489/sp.umavibe.com.sp404 i/openglrenderer﹕ initialized egl, version 1.4 06-20 02:02:57.857  28473-28489/sp.umavibe.com.sp404 w/egl_emulation﹕ eglsurfaceattrib not implemented 06-20 02:02:57.857  28473-28489/sp.umavibe.com.sp404 w/openglrenderer﹕ failed set egl_swap_behavior on surface 0xab163c00, error=egl_success 

try - v.setvisibility(view.visible);

you making invisible button how going click event. have make visible perform click event. code -

 btn.setvisibilty(view.visible);  btn.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             toast.maketext(myandroidappactivity.this,             "imagebutton clicked!", toast.length_short).show();                  v.setvisibility(view.invisible);                  mediaplayer mp = mediaplayer.create(getapplicationcontext(), r.raw.kick);                 mp.start();          } }); 

and add following line in layout-

  android:clickable="true"  

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -