嗨,当用户点击按钮时,我真的需要帮助让Android TTS从预先填充的textview中读取
我的布局文件目前包含1x按钮1x textview和1x imageView
任何参考或想法都会有很大的帮助。
这是我的代码
public class Bulbasaur extends Activity{
ListView l;
ImageView img;
TextView tv1;
Button btn1;
MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bulbasaur);
img = (ImageView)findViewById(R.id.imageView2);
img.setImageResource(R.drawable.national001);
tv1 = (TextView)findViewById(R.id.textView2);
TextToSpeech tts = new TextToSpeech(this, this);
tts.setLanguage(Locale.US);
tv1.setText("Dex Entry 001:\n" +
"Bulbasaur can be seen napping in bright sunlight.\n" +
"There is a seed on its back.\n" +
"By soaking up the sun's rays, \n" +
"the seed grows progressively larger.");
btn1 = (Button)findViewById(R.id.cryBtn);
mp = MediaPlayer.create(this, R.raw.bulbasaur);
btn1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
mp.start();
}
});
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// API 5+ solution
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
好的,谢谢你的帮助:) 但现在它正在崩溃这些错误
Process: net.metaruptdonations.MetaDex, PID: 1775
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.metaruptdonations.MetaDex/net.metaruptdonations.MetaDex.Bulbasaur}: java.lang.ClassCastException: net.metaruptdonations.MetaDex.Bulbasaur cannot be cast to android.speech.tts.TextToSpeech$OnInitListener
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
答案 0 :(得分:0)
foreach( $_POST as $value ) {
if (strpos($_POST,'ProductID') !== false) {
//Store in associative array
}
}