嘗試在你的班級申報你的int i;
。我相信這會幫助你避免使用最終修飾符。
public class MyActivity extends Activity {
int i;
public void onCreate(Bundle savedInstanceState) {
...
tv.setOnClickListener(new OnClickListener()
{
public void OnClick(View v){
String speech = list.get(i).toString();
tts.speak(speech,TextToSpeech.QUEUE_FLUSH,null);
}
});
...
}
}
或將此代碼String speech = list.get(i).toString(); tts.speak(speech,TextToSpeech.QUEUE_FLUSH,null);
轉換爲另一種方法。例如:
tv.setOnClickListener(new OnClickListener()
{
public void OnClick(View v){
speak();
}
});
__
public void speak(){
String speech = list.get(i).toString();
tts.speak(speech,TextToSpeech.QUEUE_FLUSH,null);
}