我有一个Spinner
,用于为列表选择排序模式(最新,最旧等)。这些条目只有排序模式的名称(例如“最新”),但选中后,我希望Spinner的标题使用不同的字符串(例如“按最新排序”)。最好将结果字符串格式化为:
String selection = ...;
String titleText = getString(R.string.spinner_title, selection);
// In strings.xml
<string name="spinner_title">Sorting by %1$s</string>
我该怎么做?
答案 0 :(得分:0)
为您的OnItemSelectedListener
Spinner
()
任何尝试这个:
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
TextView selectedText = (TextView) parent.getChildAt(0);
if (selectedText != null) {
selectedText.setText("YOUR TEXT HERE"); //change text when item is selected
}
}
您还可以更改spinner