[英]How can i set a default country code on my Android application
I want to make a certain country code to becomes default but right now it comes in ascending order. 我想使某个国家/地区代码成为默认代码,但现在它以升序排列。
How can I achieve that? 我该如何实现?
Here is sample code: 这是示例代码:
private void initViews() {
registrationBean = new RegistrationBean();
viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper_registration);
viewFlipper.setDisplayedChild(0);
llVerification = (LinearLayout) findViewById(R.id.ll_registration_mobile_otp);
txtVerificationLabel = (TextView) findViewById(R.id.txt_registration_mobile_otp_label);
spinnerCountryCodes = (Spinner) findViewById(R.id.spinner_registration_mobile_country_code);
countryListBean = AppConstants.getCountryBean();
Collections.sort(countryListBean.getCountries());
List<String> countryDialCodes = new ArrayList<>();
for (CountryBean bean : countryListBean.getCountries()) {
countryDialCodes.add(bean.getDialCode());
}
Add the default country code in the list at the 0th index after for loop like: 在循环之后,在列表的第0个索引处添加默认国家代码,例如:
for (CountryBean bean : countryListBean.getCountries()) {
countryDialCodes.add(bean.getDialCode());
}
countryDialCodes.add(0, yourDefaultCountryCode);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.