如何更改微调器的默认文本

时间:2015-12-21 12:23:48

标签: android android-spinner

我在我的代码中使用了三个微调器,我为三个微调器分配了一个数组,但我想更改三个微调器的默认文本。我在微调器中获取了数组细节。

Spinner sp1,sp2,sp3;
ArrayAdapter<CharSequence> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_carrer_seq);
    apply = (Button) findViewById(R.id.button3);
    sp1 = (Spinner) findViewById(R.id.spinner);
    sp2 = (Spinner) findViewById(R.id.spinner2);
    sp3 = (Spinner) findViewById(R.id.spinner3);

    adapter = ArrayAdapter.createFromResource(this,R.array.current, R.layout.spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp1.setPrompt("Developers(2-3 years)");
    sp1.setAdapter(adapter);
    sp2.setPrompt("Senior Developers(4-5 years)");
    sp2.setAdapter(adapter);
    sp3.setPrompt("Project Lead(6-7 years)");
    sp3.setAdapter(adapter);

spinner_item.xml

<?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:textColorHint="@color/text"
    android:textColor="#808080"/>

0 个答案:

没有答案