在EditText中显示微调器内容

时间:2014-08-27 10:07:44

标签: android

我想在editext中显示我的微调器对象的内容,但它只显示内容位置,即0,1,2,3。知道如何做到这一点。 这是我的代码

public void onItemSelected(AdapterView<?> parent, View view, 
        int pos, long id) {
    parent.getItemAtPosition(pos);

    courseDay.setText(String.valueOf(pos));

}

这是微调器对象的内容

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="days_array">
        <item>Monday</item>
        <item>Tuesday</item>
        <item>Wednesday</item>
        <item>Thursday</item>
        <item>Friday</item>
        <item>Saturday</item>
        <item>Sunday</item>
    </string-array>
</resources>

2 个答案:

答案 0 :(得分:0)

改变这个..

courseDay.setText(String.valueOf(pos));

courseDay.setText(yourspinner.getSelectedItem().toString());

或者

courseDay.setText(parent.getItemAtPosition(pos).toString());

答案 1 :(得分:0)

请尝试这种方式,希望这有助于您解决问题。

    private TextView courseDay;
    private Spinner spinner;
    private HashMap<String, String> questionMap;
    private String[] daysArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.arrayact);

        courseDay = (TextView) findViewById(R.id.courseDay);
        spinner = (Spinner) findViewById(R.id.spinner);
        daysArray = getResources().getStringArray(R.array.days_array);

        // set your spinner adapter code here

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                courseDay.setText(daysArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    }