Reputation: 1231
I've got a spinner working where onItemSelected
outputs a Toast. I want it to display a string value in a textview instead. So how would you rewrite the below method to show a string in a textview called denomiTV:
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext()), "Your Selection is: " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
I tried this, but Eclipse says that .setText
is not correct here:
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
denomiTV.setText(parent.getContext(), "Your selection is:" +
parent.getItemAtPosition(pos));
}
Upvotes: 1
Views: 3249
Reputation: 2026
Try this Code..
denomiTV.setText("Your Selection is : " + parent.getSelectedItem().toString());
Upvotes: 0
Reputation: 3771
You don't need parent.getContext()
as a parameter for a TextView, take a look at TextView.setText(java.lang.CharSequence).
This is what you want:
denomiTV.setText("Your selection is:" + parent.getItemAtPosition(pos));
Upvotes: 0
Reputation: 83313
setText()
takes a single CharSequence
argument... you shouldn't be passing in a Context
.
denomiTV.setText("Your selection is:" + parent.getItemAtPosition(pos));
Upvotes: 3