这是我的代码:
package com.testotspeech;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class AndroidTestToSpeechActivity extends Activity implements
TextToSpeech.OnInitListener, OnItemSelectedListener {
/** Called when the activity is first created. */
private TextToSpeech tts;
private Button btnSpeak;
private EditText txtText;
private ArrayList<String> itemsList;
private Spinner spinner;
private String contry_name;
private ArrayAdapter<String> dataAdapter;
private TextView textview;
private Iterator itr;
private String[] t = {"Please Select An Item"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("----------",Arrays.toString(Locale.getAvailableLocales()));
itemsList = new ArrayList<String>();
itemsList.add(Arrays.toString(Locale.getAvailableLocales()));
spinner = (Spinner)findViewById(R.id.spinner1);
spinner.setOnItemSelectedListener(this);
dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,t);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spinner.setAdapter(dataAdapter);
textview = (TextView)findViewById(R.id.textView1);
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
txtText = (EditText) findViewById(R.id.txtText);
// button on click event
btnSpeak.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
speakOut();
}
});
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.ENGLISH);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
btnSpeak.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
if (position == 0)
{
}
else
{
}
}
public void onNothingSelected(AdapterView<?> parent) {
textview.setText("");
}
}
编辑:
我想要做的是,当我单击 thw 微调器时,它会折叠/打开,并且我将拥有它自己的每个项目和盒子,并且它将排成一行,例如我单击了我现在将在其下方看到的微调器:
你好
再见
丹尼尔
现在,如果我单击 Hello,它将把 Hello 放在 textView1 中,如果我单击 Bye,它也会把它放在 textView1 中,依此类推。但是我希望微调器设计的图形是,当我单击它时,它会向下折叠并连续显示项目,这样我就可以单击并单击并选择每个项目。
现在我所做的只是将微调器添加一个文本“请选择一个项目”,我上传了我希望它是什么样的图像,例如: