gpt4 book ai didi

android - 将 Spinner 添加到设计器后如何在 Eclipse Android 中使用它?

转载 作者:行者123 更新时间:2023-11-29 22:05:11 25 4
gpt4 key购买 nike

package com.testotspeech;

import java.util.ArrayList;
import java.util.Arrays;
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.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class AndroidTestToSpeechActivity extends Activity implements
TextToSpeech.OnInitListener {
/** 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;

@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);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,itemsList);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);

contry_name=String.valueOf(spinner.getSelectedItem());
System.out.println(contry_name);


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.);

我有一些问题。在运行应用程序时,在我做出任何选择之前,首先在微调器中我看到所有这样的项目:[en, en_AU, en_BE,en_BW...等等。我希望当我单击微调器的向下箭头时,我会一个接一个地看到一行中的所有项目,当我选择其中一个项目时,它将用作 LOCALE

所以我需要以某种方式解决这个问题。

第二件事是在 int result = tts.setLanguage(Locale.); 中选择项目时如何使用 contry_name 字符串?

现在是:int result = tts.setLanguage(Locale.ENGLISH);但我希望它成为从微调器中选择的项目。

最佳答案

      package com.validation;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;



public class Validation_edittextActivity extends Activity {
/** Called when the activity is first created. */



Spinner country_spinner;

String[] COUNTRIES = new String[] {
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
"Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
"Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium"};


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

country_spinner=(Spinner)findViewById(R.id.spinner1);

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,COUNTRIES);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
country_spinner.setAdapter(dataAdapter);


String contry_name=String.valueOf(country_spinner.getSelectedItem());
System.out.println(contry_name);
}

关于android - 将 Spinner 添加到设计器后如何在 Eclipse Android 中使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10908781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com