从Spinner动态更改TextView的文本

时间:2012-02-10 09:05:56

标签: android

我是Android新手。 当我从TextView中选择任何项目时,如何动态更改Spinner的文字。

问候。

我正在使用的代码

    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 个答案:

答案 0 :(得分:6)

试试这段代码

mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
    {
         textView.setText(mSpinner.getSelectedItem().toString());
    }
}