当我在中设置文本时TextView
,它的文本在转到correctCondition()
方法后会发生变化;但我想在去之前更改文本correctCondition()
。所以TextView
当我单击按钮时这会改变,然后运行进一步的操作。
我想同时播放声音“一”和显示文本“1”
在这里我添加一些代码
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 {
one = 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();
}
提前致谢