简体   繁体   English

在微调框适配器中更改TextView布局的文本

[英]Change text of a TextView Layout inside spinner adapter

I have layout that contains a TextView which I am using in a spinner. 我的布局包含一个正在微调器中使用的TextView。 How to change android:text at the runtime depending on my spinner. 如何根据我的微调器在运行时更改android:text

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
  android:id="@android:id/text1"
  style="?android:attr/spinnerItemStyle"
  android:singleLine="true"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:ellipsize="marquee"
  android:textSize="18sp"
  android:textColor="#808080"
  android:text="@string/month"/>

If you are looking to find the text of the currently selected item in the spinner, and then setting it to another textview this is what you need to do 如果要在微调器中查找当前选定项目的文本,然后将其设置为另一个textview,则需要执行此操作

Spinner spinner = (Spinner) findViewById(R.id.idOfSpinner);
TextView textView = (TextView)findViewById(R.id.idOfTextView);

textView.setText(spinner.getSelectedItem().toString());

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM