2 markdowneide markdowneide 于 2013.03.13 15:35 提问

如何动态的改变 Spinner 中 TextView 的文本?

当我从 Spinner 中选择任何一项 items 时,如何动态的改变TextView的文本?
我使用的代码:

 private Spinner paidIn = null;  
     paidIn = (Spinner) findViewById(R.id.paidIn);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                 this, R.array.currencies, android.R.layout.simple_spinner_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         paidIn.setAdapter(adapter);  


     paidIn.setOnItemSelectedListener(new OnItemSelectedListener() {

                    @Override
                    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
                    {
                        setStrTypeExpense(); // my Function, i want to call to change Textview
                    }
                }  

1个回答

xiaoyan_12
xiaoyan_12   2013.03.14 11:11
已采纳

试一下下面的代码:

mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
    {
         textView.setText(mSpinner.getSelectedItem().toString());
    }
}
Csdn user default icon
上传中...
上传图片
插入图片