java - Setting text for TextView not working properly -
when set text in textview
, text changes after going correctcondition()
method; want change text before going correctcondition()
. textview
change when click button, , further operations run.
i want play sound "one" , display text "1" @ same time
here add code in
image1.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { if (mclicked == false) { mclicked = true; count = count + 1; numberwrite.settext("" + count); one(); correctcondition(); } } }); private void one() { thread tr = new thread(new runnable() { @override public void run() { assetfiledescriptor one; try { 1 = mactivity.getassets().openfd( "counting/one.mp3"); mediaplayer counting = new mediaplayer(); counting.setdatasource(one.getfiledescriptor(), one.getstartoffset(), one.getlength()); one.close(); counting.prepare(); counting.setvolume(1f, 1f); counting.start(); counting.setoncompletionlistener(new oncompletionlistener() { public void oncompletion(mediaplayer mp) { mp.release(); } }); } catch (ioexception e1) { e1.printstacktrace(); } } }); tr.start(); } public void playcorrectbeep() { thread t = new thread(new runnable() { @override public void run() { mediaplayer correctmp = new mediaplayer(); try { assetfiledescriptor correct = mcontext.getassets().openfd( "correct.mp3"); correctmp.setdatasource(correct.getfiledescriptor(), correct.getstartoffset(),correct.getlength()); correct.close(); correctmp.prepare(); correctmp.start(); correctmp.setoncompletionlistener(new oncompletionlistener() { public void oncompletion(mediaplayer mp) { mp.release(); } }); } catch (illegalargumentexception e) { e.printstacktrace(); } catch (illegalstateexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } }); t.start(); }
thanks in advance
your switch needs "break", this:
switch (v.getid()) { case r.id.imageview1: if (mclicked == false) { mclicked = true; count = count + 1; numberwrite.settext(""+ count); toast.cancel(); soundmanager.one(); correctcondition(); } break; // add line }
furthermore, you should not let correctcondition() method run on ui-thread. instead, let soundmanager.one(); run in separate thread.
public void one() { thread t = new thread(new runnable) { public void run() { counting = new mediaplayer(); try { counting.setdatasource(one.getfiledescriptor(), one.getstartoffset(), one.getlength()); one.close(); counting.prepare(); counting.setvolume(1f, 1f); counting.start(); counting.setoncompletionlistener(new oncompletionlistener() { public void oncompletion(mediaplayer mp) { mp.release(); } }); } catch (ioexception e) { e.printstacktrace(); } } }; t.start(); }
Comments
Post a Comment