當我從 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
}
}
試一下下面的代碼:
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
textView.setText(mSpinner.getSelectedItem().toString());
}
}