gpt4 book ai didi

android - 从微调器中检索选定的项目?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:28:10 25 4
gpt4 key购买 nike

我正在尝试检索选择的值微调器,我使用了以下代码

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Object item = parent.getItemAtPosition(pos);
}
public void onNothingSelected(AdapterView<?> parent) {
}
});

但是我不能在函数外使用 item 的值!我是 java 的新手,请有人帮助我..我尝试在android中实现语音识别

     public void speakButtonClicked(View v)
{
startVoiceRecognitionActivity();
}

/**
* Fire an intent to start the voice recognition activity.
*/
private void startVoiceRecognitionActivity()
{
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);


intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
startActivityForResult(intent, REQUEST_CODE);
}

/**
* Handle the results from the voice recognition activity.
*/
@Override
protected
void onActivityResult(int requestCode, int resultCode, Intent data)
{


if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
{
// Populate the spinner with the String values the recognition engine thought it heard

ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
final Button button12=(Button)findViewById(R.id.button12);

final Spinner Speech_spinner=(Spinner)findViewById(R.id.spinner3);


Speech_spinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
Speech_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Text = parent.getItemAtPosition(pos).toString();

}
public void onNothingSelected(AdapterView<?> parent) {
}
});

button12.setText(Text);




}
super.onActivityResult(requestCode, resultCode, data);


}

button12 没有值

最佳答案

像这样使用最终对象:

final Object item;

在 onCreate 之外

关于android - 从微调器中检索选定的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700905/

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