[英]How can i set a default country code on my Android application
我想使某個國家/地區代碼成為默認代碼,但現在它以升序排列。
我該如何實現?
這是示例代碼:
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());
}
在循環之后,在列表的第0個索引處添加默認國家代碼,例如:
for (CountryBean bean : countryListBean.getCountries()) {
countryDialCodes.add(bean.getDialCode());
}
countryDialCodes.add(0, yourDefaultCountryCode);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.