Hi I really need some help with getting Android TTS to read from a pre-populated textview when the user clicks a button
my layout file currently consists of 1x button 1x textview and 1x imageView
any references or Ideas will be of great help.
here's my code
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);
}
}
}
ok thanks for the help :) but now it is crashing with these errors
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)