对不起,你能帮助我吗?我正在申请儿童学习。以" EditText"的形式编写字母表的应用。我希望这个文本来自/ raw。我有来自/ raw
的A.mp3 - Z.mp3MediaPlayer mplayer;
Button play;
private final View.OnClickListener playButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// play
if (mplayer != null) {
mplayer.start();
}
}
};
.........
.........
.........
play = (Button) findViewById(R.id.button1);
play.setOnClickListener(playButtonListener);
mplayer = MediaPlayer.create(this, R.raw.(txtToDisplay)); <------- this is error
}
.........
.........
.........
//prediction.name is data storage
txtToDisplay = prediction.name;
showText1.setText(txtToDisplay);
我的数据存储是&#34; prediction.name&#34;或者txtToDisplay。 Prediction.name是A,B,C,D,E,F,G,H ......,Z。我的声音在/ raw A.mp3,B.mp3。 C.mp3 ...,Z.mp3
这是我的java
package com.example.belajargesture;
import java.util.ArrayList;
import android.app.Activity;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.Prediction;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements
OnGesturePerformedListener {
private GestureLibrary mLibrary;
EditText showText1;
String txtToDisplay = "";
//musik
MediaPlayer mplayer;
Button play;
//musik
//musik
private final View.OnClickListener playButtonListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// play
if (mplayer != null) {
mplayer.start();
}
}
};
//musik
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!mLibrary.load()) {
finish();
}
GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
//musik
play = (Button) findViewById(R.id.button1);
play.setOnClickListener(playButtonListener);
mplayer = MediaPlayer.create(this, R.raw.a);
//musik
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
showText1 = (EditText) findViewById(R.id.editText1);
// We want at least one prediction
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
// We want at least some confidence in the result
if (prediction.score > 1.0) {
// Show the spell
txtToDisplay = prediction.name;
showText1.setText(txtToDisplay);
}
}
}
}