1

我想在文本视图中显示微调器内容。我可以在文本视图中显示微调器内容,但只显示第一个元素,如果 ai 更改项目,文本视图不会更改

    Spinner sp = (Spinner) findViewById(R.id.cbTipoInspeccion);
    ArrayAdapter adapter = ArrayAdapter.createFromResource(
        this, R.array.tipoPrioridad, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp.setAdapter(adapter);  

    tvMostrar=(TextView)this.findViewById(R.id.tvSpinnerContent);

  String Text = sp.getSelectedItem().toString();

    tvMostrar.setText(Text.toString());
4

1 回答 1

2

您需要在微调器上设置 OnItemSelectedListener:

sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

  onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    //update your TextView
    tvMostrar.setText(sp.getSelectedItem().toString());
  }

  onNothingSelected(AdapterView<?> parent) {
    //
  }

})

查看SpinnersOnItemSelectedListener的文档。

于 2012-11-15T18:53:28.797 回答