简体   繁体   English

在文本视图中显示微调内容

[英]show spinner content in a textview

i want show spinner content in a textview.我想在 textview 中显示微调内容。 I can show spinner content in a textview but only show the first element and if ai change the item, the textview dont change我可以在 textview 中显示微调内容,但只显示第一个元素,如果 ai 更改项目,则 textview 不会更改

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

You need to set an OnItemSelectedListener on your spinner:您需要在微调器上设置 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) {
    //
  }

})

Look at the documentation on Spinners and OnItemSelectedListener .查看有关SpinnersOnItemSelectedListener的文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Spinner中获取选定项以显示TextView - How to get Selected item in a Spinner to show a TextView Android的不同选择微调器显示不同的textview - Android different selection spinner show different textview 是否可以在弹出窗口中显示微调器或自动完成的textview? - Is it possible to show a spinner or autocomplete textview on popup window? 如何在微调器上将TextView的文本设置为所选项目的内容? - How to set the text of a TextView to the content of a selected item on a spinner? Spinner + edittext的内容到另一个页面(textview)(android) - content of spinner+edittext to another page(textview)(android) 如何正确显示TextView下方的弹出菜单,类似于Spinner? - How to correctly show a popup menu below a TextView, similar to Spinner? 在一个活动中显示从微调器到另一个活动中的文本视图的选定值 - Show Selected value from spinner in one activity to the textview in another activity Spinner show里面的TextView显示com.jeanjn.guiadeacademia - TextView inside of Spinner show com.jeanjn.guiadeacademia 显示文本视图的冗长内容作为Toa​​st消息android - Show lengthy content of a textview as a toast message android 如何在Android TextView中显示PHP内容? - How to show a PHP content in a Android TextView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM