【发布时间】:2018-07-10 12:53:20
【问题描述】:
我想修剪用户在 Spinner 中的选择。当用户选择他的国家(例如“+232 塞拉利昂”)时,当项目被选中并且微调器关闭时仅显示“+232”。
提前感谢您的建议。
// I have two arrays of String that i join to make one
String[] phoneCodes ={"232", "44", "1"};
String[] countries = {"Sierra Leone", "United Kingdom", "United States"};
String[] phoneCodesCountries = new String[3];
// Here i join those two arrays, for example "+232 Sierra Leone"
for (int i = 0; i < phoneCodes.length; i++) {
phoneCodesCountries[i] = "+" + phoneCodes[i] + " " + countries[i];
}
// Setting the adapter to phoneCodesArray
ArrayAdapter<String> phoneCodesArray = new ArrayAdapter<String>(RegisterActivity.this, android.R.layout.simple_spinner_item, phoneCodesCountries);
phoneCodesArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spPhoneCodes.setAdapter(phoneCodesArray);
【问题讨论】:
-
您找到解决方案了吗?
标签: android spinner onitemselectedlistener