Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android微调器位置未更新_Java_Android - Fatal编程技术网

Java Android微调器位置未更新

Java Android微调器位置未更新,java,android,Java,Android,我有一个填充了字符串数组的微调器。按下按钮时,将填充微调器。输出始终为game_0,即使我使用微调器并选择say game_3。这是因为它在函数中吗 public void game(View view) throws IOException { myText=""; TextView myTextView= (TextView)findViewById(R.id.textView1); String game_list[] = {"game_0","ga

我有一个填充了字符串数组的微调器。按下按钮时,将填充微调器。输出始终为game_0,即使我使用微调器并选择say game_3。这是因为它在函数中吗

    public void game(View view) throws IOException {    
    myText="";
    TextView myTextView= (TextView)findViewById(R.id.textView1);
    String game_list[] = {"game_0","game_2","game_3","game_3","game_4","game_5"};
    for(int i=0; i<game_list.length; i++){
    myText = myText + game_list[i] +"\n";
    }
    Spinner spinner = (Spinner) findViewById(R.id.spinner);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_item, game_list); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spinner.setAdapter(adapter);
    String text = spinner.getSelectedItem().toString();
    myTextView.setText("");
    myTextView.append(text);
   }
publicsvoid游戏(视图)抛出IOException{
myText=“”;
TextView myTextView=(TextView)findViewById(R.id.textView1);
字符串game_list[]={“game_0”、“game_2”、“game_3”、“game_3”、“game_4”、“game_5”};

对于(int i=0;i您何时调用
游戏(视图v)
方法?微调器初始化
微调器.setAdapter(适配器);
和提取所选值的行之间没有用户操作的空间,该值显然(默认情况下)是数组的第一个…”游戏0“

您可以使用OnItemSelectedListener在微调器上侦听用户操作,或者使用带有单击侦听器的按钮在提交时检查微调器值

以下是应用于微调器的选定侦听器的示例:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {


        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
            // here get the selected value and do whatever you want
    }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // ignore this if you're not going to provide a "no-selection" option
        }
    });
spinner.setOnItemSelectedListener(新的OnItemSelectedListener(){
@凌驾
已选择公共视图(适配器视图arg0、视图arg1、内部arg2、,
长arg3){
//在这里获取所选的值并执行任何您想要的操作
}
@凌驾
未选择公共无效(AdapterView arg0){
//如果您不打算提供“无选择”选项,请忽略此选项
}
});